itcdr
asked on
bash script + cron (how to wait for condition to start)
I have a bash script which is scheduled as a cronjob to run each day. However, I want it to wait for an ftp update before starting. So it should it first check if a file has been updated on an ftp server, if so then start, if not then wait an hour and try again. After 3 hours if it's still not updated then don't run today.
I already have the script to check for an ftp update. I just need to know how to wait for it to return true. Any ideas?
I already have the script to check for an ftp update. I just need to know how to wait for it to return true. Any ideas?
If you script to check for ftp update, use "exit $x" where x is your exit status, then you should be able to track the exit status from your second script.
ASKER
Yes, but how do I set it so if it's not ready to wait an hour before checking again. And after 3 times (3 hours) quit if there is still no update.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't realize there was a sleep program in linux. I just want to make sure that doing something like this the program won't just timeout and quit before it retries. What do you think?
hmm.. sleep don't really have a timeout problem. I am not aware of any problem with that. Normally I know that we have problem that a script doesn't finish on time and we have to break it (force timeout in the bash script) but not the other way around. So, this should be fine.
ASKER
Sounds good. Here is my new startup script I will set for my update.
#!/bin/bash
checkFTP() {
#My code to check for FTP update, return 1 if there was one
}
for i in 1 2 3
do
checkFTP
if [ $? -eq 1 ]; then ./my_script; exit; fi
sleep 1h
done
Thanks for your help!
#!/bin/bash
checkFTP() {
#My code to check for FTP update, return 1 if there was one
}
for i in 1 2 3
do
checkFTP
if [ $? -eq 1 ]; then ./my_script; exit; fi
sleep 1h
done
Thanks for your help!
No worries. Thanks for the points