Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

bash script + cron (how to wait for condition to start)

Posted on 2006-11-15
7
3,197 Views
Last Modified: 2011-08-18
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?
0
Comment
Question by:itcdr
  • 4
  • 3
7 Comments
 
LVL 24

Expert Comment

by:slyong
ID: 17950907
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.
0
 
LVL 1

Author Comment

by:itcdr
ID: 17950972
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.
0
 
LVL 24

Accepted Solution

by:
slyong earned 500 total points
ID: 17951102
Just try to write a sample script for you...

#!/bin/sh
# check.sh just return an exit status assuming this is your ftp update script...
exit 1

#!/bin/bash
# test.sh test if ftp update script status code is 0
for i in 1 2 3
do
  ./check.sh
  if [ $? -eq 0 ]
  then
    echo $i "yes"
    break;
  fi
  echo $i "no"
  sleep 1h
done
exit 0
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:itcdr
ID: 17951216
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?
0
 
LVL 24

Expert Comment

by:slyong
ID: 17951436
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.
0
 
LVL 1

Author Comment

by:itcdr
ID: 17951475
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!
0
 
LVL 24

Expert Comment

by:slyong
ID: 17951500
No worries.  Thanks for the points
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
OwnCloud Development and/or customization.. 19 1,129
Expect & sshpass package for Solaris 10 x86 15 959
linux / python expert needed 3 98
improve Shell script 5 155
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question