The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [shell-script]

Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

1,300 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
1answer
88 views

dash maximum variable length under systemd

I have a shell script that uses a single variable as an associative array (one KEY=VALUE per line). Throughout the execution of the script, the variable is manipulated to add, remove or modify ...
5
votes
1answer
543 views

Logging the output of remote commands on multiple ssh servers without delay

I've written a simple bash script that ssh's into 3 hosts (2 remote, 1 my own for testing) and runs a long running gui program that outputs text to the terminal that I'd like to log. #!/bin/bash ssh ...
5
votes
1answer
133 views

How to create a real copy of file descriptor stdout and stderr without using unbuffer / script / tee just with bash built-ins?

My goal is to duplicate, redirect all output (stdout and stderr) of an application (apt-get) to a file while retaining the usual behavior of the application (apt-get), stdout and stderr. How to ...
5
votes
1answer
1k views

Launch background process from sh and close the terminal

How can this be achieved in sh (not bash!)? nohup sh -c 'helper-bcpy.sh "$0" "$1" "$2" "$3"' "$num" "$full_path" "$log" "$log_finished" >/dev/null & I would have expected it to send the ...
5
votes
1answer
333 views

How to overwrite file residing on ESP at Linux boot

I have a 64-bit dual-boot system running Windows 7 and Linux Mint 17 Cinnamon. I use rEFInd to graphically choose which system to boot. A little bit about rEFInd: It is an EFI bootloader. It uses ...
5
votes
0answers
240 views

Get notified from avahi

After looking for a zero-conf browser valid implementation I realised that inside my linux machine (ubuntu) I already have avahi and typing: avahi-browse -alr I get a complete list of all devices ...
4
votes
1answer
277 views

How to toggle audio between PC and TV set?

I created a script that toggles audio output between PC and TV set connected via HDMI. It looks so: inactive_sink_id=$(pacmd list-sinks | grep -E "[^*] index: [0-9]+" | sed -r -e "s/.*([0-9]+)/\1/g") ...
4
votes
4answers
183 views

Compare lines and upgrade two different files

I have a couple of text files with the following features: $ cat file_1 Line A Line B Line C Line D $ cat file_2 Line A Line added 1 Line B Line D Line added 2 They are such that file_1 has some ...
4
votes
1answer
1k views

TOR hidden service not always accessible through cURL. Takes multiple tries

When I try to access a hidden service on TOR using cURL, for some reason I'm not getting access to the site 100% of the time. Many times it returns "curl: (7) Can't complete SOCKS5 connection to 0.0.0....
4
votes
2answers
910 views

Bash script function that changes the value of a variable

I'd like to make a function for a BASH script that changes the value of one of its arguments, that is a variable. The function that I did is: chck_rgx () { # Checks that the given name for a user/...
4
votes
4answers
1k views

find closest matching folder

What is the best way to sort the results of $ find . -name scripts -type d by the occurrences of '/' and then choose the first result? I want to create a function that would cd down to a common ...
4
votes
1answer
1k views

Checking if a specific key is pressed in shell script

Is there a way I can check if a specific key is pressed in a shell script which is running in background. Consider I am running a shell script which has to play a play list of songs as soon as I press ...
4
votes
0answers
307 views

Understanding line numbers reported when using eval

Okay, so I'm stuck working with a shell script that needs to use eval (I know, I know, ultimate evil etc…) however I'm having difficulty debugging some of the line numbers being thrown out by errors. ...
4
votes
3answers
5k views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing happens!...
4
votes
1answer
1k views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
3
votes
0answers
34 views

Tool to edit CSS from script (better than `sed`)

I need to modify CSS file from a script and I want to make sure I don't break it. Is there any command line tool that understands CSS structures and allows to edit them? TLDR; I need jq command but ...
3
votes
2answers
79 views

Parsing csv file to filter rows basing on a matching set of characters from a column value

Consider the following csv file: A,3300 B,8440 B,8443 B,8444 C,304 C,404 M,5502 M,5511 The real csv file is really big (around 60,000 rows) but I only included a small version for ...
3
votes
3answers
75 views

How to grep data of a new line when capturing a keyword?

I have a file which contains below sample line having a common keyword P00001121 in each line. [H00,P00001121] CHANNEL__OPEN:TCP_ADDRESS='10.32.130.202' TCP_PORT='80'" [H00,P00001121] COMMS_QUEUING:...
3
votes
0answers
56 views

Git - prune every whitespace-separated word originally introduced by specific author in project's history

We have a project under git revision control with only a single branch. We need to remove every new whitespace-separated word that was introduced for the first ever time in a given file by a specific ...
3
votes
1answer
269 views

Execute script prior to cinnamon logout (unsing MDM or other display manager)

I'm using cinnamon as desktop environment on my Linux Mint system. I want to automate a backup using unison: Unison shall be executed prior to each logout off my session. So I was looking for a ...
3
votes
1answer
2k views

Execute multiple command through SSH using sudo

#!/bin/bash while IFS="," read -r f1 f2 do username="testuser" SSHPASS='abcde' sshpass -e ssh -t "$username@$f1" "sudo su - root -c 'yum -y install wget'"< /dev/null ; done < Input.txt Now ...
3
votes
0answers
476 views

Restore backup of $HOME via rsync

I'm using Opensuse Leap 42.2 and use zypper as my preferred package manager. I did regular incremental updates of my home directory to an external drive via the script: #!/bin/bash source="/home/...
3
votes
1answer
219 views

Signal not received by script run using sh -c

I have a script which sleeps for 3 minutes before running a time consuming command. I want the script to exit if it receives SIGINT only while it is sleeping, and not when it is executing the long ...
3
votes
1answer
1k views

error: Macro % has illegal name (%define)

I have a build support script for building my packages. Now I want to automatically set the Version in my spec files. I use the macro %{auto_version} for that. In my script I want to invoke rpmbuild -...
3
votes
0answers
762 views

xdotool prints 8 instead of Tab

I'm currently working on a "autotype"-script for pass. In oder to do that, I need to type the username, press 'Tab' and then type the password. For testing I'm using the following code: WID=$(...
3
votes
1answer
112 views

How to count subprocesses that reached certain state

I have a bash script that launches >20 subprocesses (functions launched with & in background) and want to include a progress indicator that tells the user how many of those subprocesses are ...
3
votes
1answer
298 views

How do I use the output of a command for a process within a loop in Bash?

I'm tring to obtain the format info of a bunch of media files in a directory. The script I have goes through each file, mentions what format its in (if it's a media file) and then exits. What I ...
3
votes
0answers
225 views

Shell script to unlock gnome-keyring for school internet upon login

My school's wifi network is not protected merely with a WPA/WPA2 password, it requires authentication (PEAP, MSCHAPv2). I can log into it fine (the credentials are in my network connections) however ...
3
votes
1answer
194 views

PHP interactive script that calls nano

I have written simple PHP programs meant for the command line that run a script to completion with the hashbang at the top: #!/usr/bin/php -q <?php //etc However I need to write a script that ...
3
votes
3answers
85 views

How to use an input file of non-exact filenames for an operation?

I have a file of filenames for files in a certain directory. However, some of the file names may: Have spaces in the original filename replaced with underscores (so directory/file with spaces ...
3
votes
1answer
1k views

Upload to youtube using shell script

I've searched the youtube API but still not clear whether this is possible. I have a shell script that uses FFMPEG to convert a video. After being converted I want to have the video automatically ...
3
votes
1answer
970 views

Startup script on Debian 8 (Jessie) with etherwake won't work

I'm attempting to remotely wake a slave machine when the master boots up through a bash script using the etherwake command to send magic packets. Both OSs are Debian 8. The full code is written below: ...
3
votes
0answers
337 views

How to use `gnome-terminal` with new client/server architecture as wrapper?

Anyone knows how to accommodate for new gnome-terminal-server magic? Before gnome-terminal got its new "client/server" architecture I used to use it as vim wrapper with great success for many years. ...
3
votes
1answer
621 views

Getting script's real absolute path in /bin/sh

I'm looking for a way to get the real absolute path to the current /bin/sh script. It should work for situations like this one: /path/to/symlink/in/PATH/somescript -> ../../Package/current/...
3
votes
1answer
1k views

Modify filenames in Makefile

For reasons that are not important here, I have a source code that I process automatically file-by-file and the processed source files are renamed in a systematic manner. For example, I start out with ...
3
votes
2answers
687 views

Bash Scripting: How do i limit the amount of options in a select loop?

When you use the select loop to present the elements of an array as an option, it will display it all at one time. Is there a way to present the options to the user for like 25 options at a time?
3
votes
1answer
920 views

Bash root to user. Best in same or separate script?

I'm working on a Linux Bash script that needs to start as root. At the end of the script, it builds a list of packages. This requires running as user. Then it will move the packages, which needs to ...
3
votes
1answer
2k views

How to kill inactive user logins on Solaris?

On a Solaris 10 server if i do a w, I get this: 12:26pm up 85 day(s), 1:13, 6 users, load average: 0.38, 0.36, 0.38 User tty login@ idle JCPU PCPU what blah pts/1 ...
3
votes
1answer
75 views

How do I process new additions to logs

I know that I can use a few tools like tail and less to view the newest additions to a growing log file. What I want to do, though, is run some sort of script at regular intervals (like cron) on the ...
3
votes
1answer
57 views

How to recognize a state of idleness for a given period in a script?

I would like to write a simple script that should work as a daemon. The only thing this daemon has to do, is to check if for a given period neither a key has been hit, nor a mouse moved, nor a ...
3
votes
0answers
238 views

unbuffer/expect swallows the rcode when its child is signaled

unbuffer is able to pass along the return code of a process under normal circumstance, but if the process you are unbuffering is killed, for instance with a segfault, I see $? as 0 while I expect 139. ...
3
votes
1answer
352 views

Securing a script a little more

I currently have the following script which works fine: #!/bin/sh user="$(zenity --entry --title="Username" --text="Username")" pass="$(zenity --password --title="Password" --text="Password")" ...
3
votes
1answer
1k views

Turning off default video output with xrandr when external monitor is connected

I'm new to bash scripting, and I'm trying to configure my video outputs so that my laptop display gets turned off when I connect an external monitor via VGA. That's the script I came up with, pretty ...
3
votes
2answers
4k views

IBM V7000 scripts for monitoring

Hello (I'm no hard core coder:), I try to develop a script to do some very basic monitoring on an IBM SVC. My goal is to get some information about the nodes and my quroum status and then send ...
3
votes
3answers
3k views

How to wait for all spawned and backgrounded processes to finish in bash script

I've looked and looked and can't find a working solution to a bash script I'm trying to create to shut a process down and wait for it and spawned processes to finish. I'm still learning a lot of Linux....
2
votes
1answer
34 views

What are the ways of hiding Shell script commands in command line due to command failure or bad input file?

I am creating a bash script for automating command line operations. I have observed that if I enter incorrect password or the input file is parsed incorrectly, the next commands from script are ...
2
votes
1answer
54 views

Restart shell script if not printing

I have a shell script that just calls a Python file in loop e.g.: for i in $(seq $start_index $end_index) do python my_script.py done The Python process halts when it is not able to generate ...
2
votes
1answer
46 views

Nested command substitution does not stop a script on a failure even if -e and shopt -s inherit_errexit are set

Suppose you have a following script sandbox.sh. (This looks similar to Command substitution inside a function does not stop the script on a failure even if -e is set, but I believe a bit different ...
2
votes
0answers
88 views

Command substitution inside a function does not stop the script on a failure even if -e is set

I have a following script sandbox.sh, #!/bin/bash set -eu -o pipefail -E function func1() { echo "FUNC1" exit 1 } function func2() { local ret ret=$(func1) echo $ret echo "(func2)This ...
2
votes
0answers
50 views

Python open screen and execute inside screen

I have a py script S1 that I would need to execute inside a screen. On an end-user point of view, I would like them to just execute another python script S2, which will open a screen and execute the ...