That's good to know, thank you. I looked at the man page and did not see how to reset the trap. After some googling, I think that a trap reset might look something like this?
Is that the correct way to reset the trap?
Also, if the script is terminated with CTRL+c (without resetting the trap), the trap settings won't effect other scripts that I run afterwards, will it? Does the trap only apply to the script that it was called from?
I should point out that in my example I used integer values and yours used the signal name(s); either one is valid. Here are the values I used(kill -l will list other values):
SIGHUP 1 death of controlling terminal or process
SIGINT 2 <Ctrl><C>
SIGQUIT 3 <Ctrl><D>
SIGTERM 15 Software termination
If you have properly used the shebang at the top of your script to identify the shell interpreter, ie. #!/bin/ksh then your script is spawned in a subshell and the trap does not need to be reset because when the script execution terminates the trap values are lost.
The point of the reset is if you have something like: trap 'ls -l' 2 (which will cause <Ctrl><C> to do a long listing) for part of your script, you'll might want to put it back with trap - 2 for normalcy.
One last thing, trap is usually used to clean up when a script is aborted so it probably is used more like:
Thank you all for your assistance - I really appreciate it. Things seem to be running smoothly at this point and are to my liking. Here is the finished version of the script:
This script suits my needs well. There may be more efficient ways to code this process, so please feel free make appropriate changes and re-post it if you like, and feel free to use it if it benefits you in some way.
Thanks again to those of you who offered assistance with getting the script to terminate with CTRL+c.
Hello,
I am running a bash script to do an rsync back on a computer running MacOS High Sierra. This is the script I am using,
#!/bin/bash
# main backup location, trailing slash included
backup_loc="/Volumes/Archive_Volume/00_macos_backup/"
# generic backup function
function backup {... (12 Replies)
Hi everyone, I'm new here and just a beginner in linux scripting.
Just want to ask for help on this one.
I am trying to create a script that will accept user input (year-month and user/s).
I wanted to have the script to continue running, until the user inputs a DATE and name/s of user/s. ... (2 Replies)
I have the following while loop that I put in a script, demo.sh:
while read rna; do
aawork=$(echo "${rna}" | sed -n -e 's/\(...\)\1 /gp' | sed -f rna.sed)
echo "$aawork" | sed 's/ //g'
echo "$aawork" | tr ' ' '\012' | sort | sed '/^$/d' | uniq -c | sed 's/*\(*\) \(.*\)/\2: \... (3 Replies)
Heyas,
Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p
The last point for motivation was... (17 Replies)
I want to run a script that calls remote ssh and if it gets hung, I want to be able to kill that part of the script and run another command in the script
for example I have a statement like this:
if ];
then
export tapes=$(for tape in $(su - nacct -c 'ssh remote1 "cat... (1 Reply)
I'm writing a bunch of scripts to automatically configure Ubuntu and I want to run the code below to remove the white dots from the login screen:
sudo xhost +SI:localuser:lightdm
sudo su lightdm -s /bin/bash
gsettings set com.canonical.unity-greeter draw-grid false
The problem is that... (3 Replies)
Hi Sir,
I am just learning bash scripting and I came across a challenge.
I need to input F11 to a script among many text inputs.
For all the text inputs i did following.
# sh test.sh < input.txt
where input.txt contains all the text inputs in new lines.
This worked fine until i... (1 Reply)
Need help in scripting . Below is the situation and need your inputs
Checking all the processes, scripts running time based on user input time . Below Example
ps -aef -o user,pid,etime,stime,args| grep sleep
<user> 28995 01:24 14:14:39 sleep 120
<user> 29385 00:52 14:15:10... (8 Replies)
I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files:
for i in 250.*; do
|| awk... (4 Replies)