![]() |
[AIX/HP-UX] ksh timedout hanged command
I have a ksh script who is calling an external script myscript1.
myscript1 -a -b -c 1>/dev/null RESULT=$? if [ $RESULT != "0" ] ; then # If 'command hanged'/failed send HPOV alert fi Sometimes, this script gets hung. I would like to be able to have a time out, lets say about 50 seconds and if the script didn't finish, I would like to kill it. Any ideas what should I do ? |
If in the particular version of AIX or HP-UX you have a fully implemented ksh, then could you run the external script in the background, have a sleep of 50 seconds in the main script, then just kill off the external script, if it's still running?
|
Hi there,
kakaka's suggestion puts you on the right track. The only down side of sleeping for 50 seconds in the main script is that you will waste time if myscript1 finishes sooner (say in 10 seconds). Here's a sample script elaborating on this idea, which may help. Quote:
|
meantime
.... script1 -a -b -c >/dev/null 2>&1 & PID=$! sleep 60 && kill -15 $PID 2>/dev/null wait $PID >/dev/null 2>&1 RC=$? thanks cliffordw, i'll take a beeter look at your example: oki now 2nd issue:: f=0 set -A BKS dir1 dir2 dir3 dir4 ...dirN while [ $f -lt ${#BKS[*]} ] do echo "files to be tar-ed ${BKS[$f]}" tar xfv ${BKS[$f]} call_function_to_check_disk_space fi DS <5Gb ==>raise alert #echo backup failed for dirA dirB....dirN # Let's say i have an unknown number of folders to archive.... #after each iteration check disk space if less then defined (5gb) show backup failed for dirA dirB....dirN ((f+=1)) done again, any ideas ? |
fritz001, what's the question, are you saying that you get the warning every time, even when there is enough disk space?
|
back online,
nope : here what i want to do :: I have a script which generate some tar archives and I have 20 big folders to archive. So set -A folders dir1 dir2 dir3 ..... dir20 f=0 [ $f -lt ${#folders[*]} ] do echo "files to be tar-ed ${folders[$f]}" tar xfv ${folders[$f]} call_function_to_check_disk_space if diskspace < 4g #Here is what i want to do: #Let's say after finishing to compress dir1 dir2 dir3 dir4 the remaining disks space is less then 4G #i want to create a second array with the failed archives (dir5 dir6 dir7 .... dir20) and to generate an echo like this :=> echo "backup failed for dir5 dir6 dir7 .... dir20. done Well, hope this time I wasn;'t to confusing... |
Hi fritz001, now that we know you're willing to try stuff ( like the trap directive ), I feel that I can say that I'd approach the backup procedure itself, a little differently.
I'd check for disk space, first, before running the tar command. Unless you're going to actually list the files in the directory you're going to back up, as in ls ${folders[$f]} then I'd call a directory, a directory, in the output messages. I wouldn't output something like "files to be tar-ed" and then show a directory name. So with the failure notification, that might look something like this: Code:
function get_disk_space_in_gb1) stop executing the tar command, and instead 2) start to put together the failure list after you reach your disk space limit. |
| All times are GMT -5. The time now is 08:34 PM. |