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!

I really need some help to write a script 1

Status
Not open for further replies.

normap

MIS
Apr 20, 2001
94
CA
I am looking for a script file which I want to run in the background every 5 minutes during a certain time each day. I would like it to look for a certain file and if it is there to run another script file to update the system. If it isn't there then run again in 5 minutes. I am not real sure how to write the script and how to set it to run when I need it run. If anyone can help me with this I would be very grateful. :)
 
As vgersh99 says you need crontab, to add a new job to crontab;
crontab -e
then edit the file adding your script and times required - yours should look something like;
0,5,10,15,20,25,30,35,40,45,50,55 7-19 * * * * /path2script


Your script should look something like this, this script will pick up $SOURCE and move it to $ENDDIR - you might like it to do something else. The mail -s bit will email you if it was a success;

#!/bin/sh
if [ -s $SOURCE ] ;
then
mv $SOURCE $ENDDIR$FILENAME
mail -s &quot;FILE COPIED SUCCESSFULLY&quot; $FATALMAIL << END
Source file found and copied to directory
END
fi
Hope that helps you huronboy



 
Thank you everyone for your help. I did exactly like you suggested and it was the solution to a problem that has been ongoing for the last 2 years!

Thanks AGAIN

[thumbsup2]
 
Glad you got the help you needed, Huronboy. I'd only add as a word of caution that if you're testing for the existence of the file every five minutes, you need to be pretty sure that the file is the complete version, rather than an 'in-process' version. This could perhaps happen if the process to create the file kicks in at say, 4:59 minutes/seconds and creates only the file name before it is picked up by your cron job, thus transferring an empty file rather than the complete version (if that is what you need to do).

I hope I've explained this clearly enough (sore head at the moment![dazed]). I know there have been discussions in various forums about how to test that a file is complete before an action is taken - I'll have a look and get back if I find anything relevant. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top