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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Terminate Unix script after 12 hours

Status
Not open for further replies.

zen2003

MIS
Jul 21, 2003
17
US
How do I write a script to terminate in 10 hours if a file is not found.
The script has to check for a file, if file not found go to sleep for 1 hour, check again....sleep....
If file not found even after 12 hours, then exit with error

thanks for your help
 
x=0
while (( $x < 12 ));
do
if [[ ! -f yourfile ]];
then
echo &quot;your file not found&quot;
sleep 3600
else
echo &quot;your file found&quot;
#if you don't want to exit, then comment &quot;exit&quot; and then add command 'sleep 3600' also.
exit
fi
((x=x+1))
done
 
Sorry, may has a typo. If the while loop not work,
change as follows:
while (( $x < 12 ));
to
while [[ $x < 12 ]];

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top