Why Crontab AT 1AM Not Work, but it does at another hour?

October 20, 2016 2.3k views
Linux Basics Linux Commands Ubuntu

Greetings.
I have created a certain number of cronjobs (15) to be executed at certain time, but Im having issues with the time of the job, for example:

 5 1 * * * Command to be executed

Doesn't run, but if I do something like this:

 5 10 * * * Command to be executed

Runs perfectly.

I don't know if this have something to do with the date/timezone that I setted to my vps.

Thank you for your attention.

6 comments
  • What makes you think the command isn't being run? Your syntax is correct, there's nothing to change.

  • Well, I have some other process that I check every day at another hour, but the ones that are configured to run at 1AM simply don't run. :(

  • My question implied that maybe they're being run but the way you're verifying that isn't correct.

    So how are you checking that the command isn't being run?

  • @ingrobertoruelas,
    I would verify is it really not running. When cronjob executes it writes when it in syslog.
    Run this basic command:

    • sudo grep CRON /var/log/syslog | less

    You will get list of all cronjobs executes. Try to find is there one that should be executed at 1 AM. If you find, well it is executing, if not, we will try to find out root of problem.

    Sample output of command
    Oct 20 00:28:01 digitalocean CRON[4332]: (sammy) CMD (Executed command)
    Oct 20 00:29:01 digitalocean CRON[4336]: (sammy) CMD (Executed command)
    Oct 20 00:30:01 digitalocean CRON[4340]: (sammy) CMD (Executed command)
    
  • This is the command that I use to check the log of the jobs that were executed:

    grep CRON /var/log/syslog 
    

    I don't know if I'm missing something, because it only shows me info about today.

  • Thank you xMudrll.
    I've already check the whole file and the jobs that I mention are not listed there, and that's why I'm thinking that I has something to do with date config.

1 Answer

This is an old one, but just stumbled across it now. Hopefully this will be useful for people still landing here from search. What I suspect was happen here was that /var/log/syslog was being rotated after the command was successfully run but before you checked the logs.

logrotate is run daily via it's entry in /etc/cron.daily/:

# ls /etc/cron.daily/
apport      bsdmainutils  logrotate  mdadm    passwd              update-notifier-common
apt-compat  dpkg          man-db     mlocate  popularity-contest

Scripts in /etc/cron.daily/ are run daily at 06:25:

# grep '/etc/cron.daily' /etc/crontab
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

So if you check /var/log/syslog after that point in time, it may not contain entries from before then. To confirm if this is why you can not find a log entry, check /var/log/syslog.1 for older ones.

Have another answer? Share your knowledge.