I have a shell script that writes some data in a file. I want to stop the script after one hour from start of execution using "EXIT 1".
how to do it. I don't want to use CRONTAB.
Would be easier if you'd post what you have in your script
Should work with ksh,bash:
my_pid=$$
trap "exit 1" USR1
( sleep 3600; kill -USR1 $my_pid ) &
# time consuming stuff here
I have the same query. please find my script below..
find . -type f +mmin +5 > /tmp/test_file
while read FNAME
do
scp -i /root/.ssh/id_dsa_noauth $FNAME myserver.com:/tmp/
done < /tmp/test_file
if there some 1000 files in the folder, the script pushes the files one by one and sometimes goes into a hang state after 1 hour. so is there a way to exit the script after 1 hour....
p.s the above script is just the core part of a big script which is designed for special purposes...
@Tuxidow: That could be optimized:
find . -type f +mmin +5 -print | xargs -I{} -n 100 scp -i /root/.ssh/id_dsa_noauth {} myserver.com:/tmp/
See man man xargs (POSIX)
I can't run the script as u suggested...
it should go in a loop...after successful copying each file should be moved to a "processed" directory and also log the status of the file move in a report.
is there any other way?