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?
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.
add a cron job to check if the script is running, if not start the script.
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