Running a script in INFINITE LOOP

Hi All,

I have a requirement as below.

I supposed to get a file from Source system once in a month. But we dont know when the source system will send the file. My script has to wait for that file in LOOP once it gets the file then it has to FTP the file.

I thought of scheduling the job once in a daily but "My requirement is to get the file ASAP else it will expire from the source system"

So can any one suggest me the best solution for this?

Thanks in Advance,

Raamc.

I don't like loops. Why not have a cron job that runs every hour, checking for the presence of this file?

If once an hour isn't frequently enough, just do a script that runs in a loop and start it with "nohup" so it continues to run even when you log out.

Running the script for every hour by using the CRON is suitable for my requirement.

Thanks for the reply.

Can i have a code for scheduling the script for every hour ,31 days in a month and 365 days a year?

And, CRON is a part of UNIX OS or do we need a buy any special licence for that?

Raamc.

You can cron every minute if you need it. crontab entry

* * * * * [[ -f /path/to/file/filename ]] && mv /path/to/file/filename /path/to/storage/

This is not a great idea because if the file is ftp'ed to your system you may get a partial file if ftp has not completed. Change the ftp process to transfer a small dummy file after the real file is already there. Then search for the dummy file and then mv both files if you find the dummy.

cron is part of unix, you system has to have crond running. Try man crond

00 */1 * * * < comannd goes here>

every hour.

And if the cron die ?

  1. add a cron job to check if the script is running, if not start the script.
  2. The script should be something like:
#!/bin/sh
# Loop forever
while :
do
# Check if cron is running
  test $(ps ax | grep -c "[c]ron") -gt 0 || /etc/init.d/crond start
#Do whatever you have to do
  echo "Hello world"
# Sleep one hour
  sleep 360
done # Start over