Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set timeout for command

Status
Not open for further replies.

barryp

Programmer
Jan 30, 2002
48
GB
I have a script which is run by CRON
It looks in a folder on a remote server for a file & if there will copy it across, process it then ON THE REMOTE SERVER move it to a 'done' folder.
Most of the time - it works
BUT all too frequently it hangs for hours on the MOVE
I use

/usr/bin/ssh -q me@xxx.xxx.xxx.xxx -i /xxxx/xxxx/.ssh/id_dsa_mfssh "mv ~/$path/export/myfile ~/path/done"

Is there some way I can set a timeout and check success/failure & retry ???

Any help much appreciated
 
Hi barryp,

Try something like this. I've not tested it but something along these lines should do the trick.

------------------------------
finished=1

while [ $finished -eq 1 ]
do
move_command & #start a s background process
procpid=$! #get process ID of last command
sleep 60 #wait 60 Secs

ps -p $procpid #is process still running

if [ $? -eq 0 ] #process is still running
then
kill -9 $procpid #kill pid and keep looping
else
finished=0 #move has finished so exit loop
fi
done
-------------------------------

Hope this helps,
M.
 
The above will need putting into a ksh script and the script will need to be called from cron.

M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top