![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [C] fgets problem with SIGINT singlal!!! | hurricane86 | High Level Programming | 1 | 01-02-2009 12:04 PM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 12:25 PM |
| Problem with handling SIGINT | JamesGoh | High Level Programming | 3 | 02-24-2008 10:39 PM |
| Cannot catch SIGINT while serial break condition occurs | gzz | High Level Programming | 13 | 11-23-2007 08:06 AM |
| AIX intercepting system calls | ramkumar.pvs | AIX | 2 | 09-29-2006 02:17 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Intercepting SIGINT in a bash script
I've written a bash script which captures video with DVgrab. Because of the nature of the tapes that I am digitizing, sometimes I want to quit capturing before the time that I set for DVgrab. When this is the case I press Ctrl-c and DVgrab exits cleanly, my problem is that there is additional information that the script prints in the terminal with 'echo' when the script runs till it's set time. When I Ctrl-c none of this information prints...
Is there a way to intercept the SIGINT ( I think this is what I want, but I could be wrong) and have it operate exactly as it does by default, but additionally echo a few varibles in the terminal? Preferably I would like to do this just in my script... and not effect the way Ctrl-c functions system wide. Not sure if it matters, but based on my reading prior to this post I wasn't sure, but I run this script in a virtual terminal in gnome on an Ubuntu (8.10) Linux machine The bit that I wanted to add when Ctrl-c is pressed looks like this: Code:
echo -e "\E[31;40m++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" echo "+ Warning - Capture Ended Early +" echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" echo -e "\E[30;47m++ Format: $FORMAT ++ Min Remaing on $destination : $minremain " echo "++ Deck: $deck_number ++ Customer: $customer " echo "++ Rec Time: $tape_length ++ Tape: $tapename" -Starcast |
|
||||
|
I ended up making it look like this, But you gave what I needed to get there, thanks.
Code:
#!/bin/bash trap 'echo -e "\E[31;40m\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n + WARNING - Early Exit +\n ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\E[30;47m\n ++ Format: $FORMAT ++ Min Remaing on $destination : $minremain \n ++ Deck: $deck_number ++ Customer: $customer \n ++ Rec Time: $tape_length ++ Tape: $tapename"' 0 |
|
||||
|
Yes, I see that.... I just finished a 2 hr tape and my warning poped up after it ran for the full allotted time and exited normally...
I changed the -2- to -0- just guessing and i thought it was working.... ( I can't for the life of me find a listing of 'trap options' explaining what each number here would do?) I switched it because the -2- option isn't ending the script? It prints my inserted code, but doesn't bring back the prompt, it just continues the script? ---------- Post updated at 04:50 PM ---------- Previous update was at 04:27 PM ---------- Ok, I spoke too soon. the -2- option does stop DVgrab (it doesn't exit the script when i press Ctrl-c before the point in the script when DVgrab starts.... Which is fine except, I also have a function that runs a countdown in my script, and this countdown continues after Ctrl-c... The countdown function looks like this: Code:
function countdown
{
local OLD_IFS="${IFS}"
IFS=":"
local ARR=( $1 )
local SECONDS=$(( (ARR[0] * 60 * 60) + (ARR[1] * 60) + ARR[2] ))
local START=$(date +%s)
local END=$((START + SECONDS))
local CUR=$START
while [[ $CUR -lt $END ]]
do
CUR=$(date +%s)
LEFT=$((END-CUR))
printf "\r%02d:%02d:%02d" \
$((LEFT/3600)) $(( (LEFT/60)%60)) $((LEFT%60))
sleep 1
done
IFS="${OLD_IFS}"
echo " "
}
Thanks -Starcast |
|
||||
|
Ok, so I turned my brain on and figured out my solution... I hate it when I catch myself getting lazy on here...
For anyone following the thread, this does what I described needing Code:
trap 'CUR=$END sleep 1 echo -e "\E[31;40m\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n+ WARNING - Early Exit + \n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ \E[30;47m\n++ Format: $FORMAT ++ Min Remaing on $destination : $minremain \n++ Deck: $deck_number ++ Customer: $customer \n++ Rec Time: $tape_length ++ Tape: $tapename" exit ' 2 And I added 'exit' at the end so that the script didn't continue after killing the countdown function -Starcast |
| Sponsored Links | ||
|
|