Hi again Nix-friends!
I don't know how many questions I've asked here up until now (got answers for most to which I'm eternally greatful), but I've got yet another question:
Say I have a script, called script.sh. This script suffers from a particular problem... sometimes it works, other times it just gets stuck. When it gets stuck I have to do the whole Ctrl+C thing and manually do whatever it is I have to do.
To get around this, I was thinking of composing a new script which will essentially run the script.sh script, time it, then stop it if after xx seconds if it is still running.
Phase 2 will just hold the commands I'll ordinarily run in case of the script.sh script failing.
Now you may ask why don't I just write the darn script with the commands I'd usually use if the script.sh script fails, right? Well, good question! Personally I'd rather would've gone that route too, unfortunately though policy forces me onto the detour...
So, how would I go about this?
Here's what I was thinking:
Quote:
script.sh &
SCRIPTTIME=`ps -efo %c%p%t | grep "script.sh" | sed -n '/grep/!p' | awk {'print $4'}`
SCRIPTPID=`ps -efo %c%p%t | grep "script.sh" | sed -n '/grep/!p' | awk {'print $3'}`
if [ $SCRIPTTIME >= "00:30" ]
then
kill -9 $SCRIPTPID
|
After the kill thing I'd insert whatever I'd have done when the script.sh script failed. Thing is though, how can I get my script to update the SCRIPTTIME variable every say 2 seconds for 40 seconds?
Thanks in advance