Parameters in crontab

I need to write a shell script which send an alert if a particular script scheduled in cron is not triggered.

My concern is that particular script which is scheduled in crontab, runs at night but it requires a file from upstream system as a feed prior to execution. it waits for that file upto 4 hours from the scheduled time and it triggers as soon the file come from upstream system. in simple words, script will wait for the file from upstream till 4 hours from the scheduled time in crontab. How I can proceed with the monitoring script which can alert me in case this script don't get triggered?

Appereciate the response from any member on this forum.

Welcome Ankit Srivastav,

How is your script waiting for up to 4 hours? Could that not have a section where the time has exceeded the limit and it fires an alert?

Alternatives might be to have your main script write a message in a log file that you alerting script can read 4 hours (and a little bit) after the main script is called in. This could be via a separate cron job or by you main script sending this in at the beginning:-

(sleep 14410  # 4 hours (and 10 seconds)
/path/to/checker.script ) &

A few more questions:-

  • What have you tried so far?
  • What would you expect you main script to do if the file has not arrived?
  • If it is a large file, how do you check that the file is complete before you start processing it?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

Kind regards,
Robin

Some of the things

  1. Did you check with cron logs?
    $ tail /var/log/cron
  2. What is the exit code of your script ? (pseudo code below)
    0 0 * * * (./script_waits_4hrs_then_fails.sh ) && ( mail -s "Success" ) || ( mail -s "Failed")
  3. May be modify the script to be more proactive and report to you before it decide to fail. ( Provide the script, we can suggest on certain "pro-activeness" for script. )
  4. If your don't want to modify the script then write another script to monitor the file and logs after the file downloaded is processed.
    Around the lines
    [list=a]
  5. Check every X mins interval if file is available at "upstream" ? in four hours of time.
  6. If file appears then check if "script" writes any logs etc. If there is some activity, we have file and it started processed.
  7. Another way is to check for any process that the script is suppose to call example database call or other connections. Any binaries etc ..
    [/list]

Hope you get your answer and share your solution.

---------- Post updated at 08:27 AM ---------- Previous update was at 08:21 AM ----------

Also if your script does give out good output and if there are not many in cron jobs. Many be adding MAIL to will get you output of script. Make sure Mail server setup is good.

MAILTO=me@domain.com