I have a cron job that runs at 1am everyday that creates two files in /tmp, called firstrun and endrun, each containing the time that a script should be run. Once in the morning and once at night. The files only have one line and looks like this:


for 8:03am.



for 5:54pm

I need a script that runs in cron that checks these two files, and if the current time is greater than what is seen in each file PLUS 5 minutes, it kicks off another script and exits. The kicker is that it only needs to run twice a day. I figure that it could delete the file once it meets the requirements and if the file isn't there exits. Of course, at 1am, the files will be put back in /tmp by the first cron job.

The idea is to only run the jobs once per day each. Not over and over, everyday. The time in the files changes everyday. Also, I should say that the script that fires off on the first file is different that the script that fires off on the second file.

Is there a simple check, fire, delete, exit script that can be put in cron and ran every 5 minutes? or an easier way to do this? I have tried several methods and have never found a way to automate this successfully.

1 Answer 1


You could try using at to schedule your jobs instead of cron.

at schedules one-time jobs to run at a predetermined time in the future. cron is good for scheduling jobs that run at regular, pre-determined intervals, but at is better for scheduling jobs that happen irregularly and/or at irregular intervals.

Read man 1 at for more information and usage.

  • I tried using 'at', and the jobs started on time, but the scripts that it ran acted weird, like they didn't calculate time and dates correctly when called using 'at'. Like they where in a different time zone. It was weird and i never figured it out. Commented Nov 11, 2016 at 17:40
  • Sounds like you have a locale or localization issue then. That doesn't sound related to at.
    – jayhendren
    Commented Nov 11, 2016 at 17:42
  • Yea, like a said, I couldn't figure it out, so I'm looking for another method. -thanks Commented Nov 11, 2016 at 17:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .