Cron – Troubleshooting Why a Crontab Job Isn’t Running

cron

I have a cron job that runs every minute on an Ubuntu 12.04 box

$sudo crontab -e
* * * * * mylogin /pathto/file.sh > /log/filelog

If I run file.sh, the bash script does some stuff and echos out runs:

$ ./file.sh 
runs

If I check the log of cron tab it shows that the job is running:

Jul 10 12:41:01 localhost CRON[1811]: (root) CMD (mylogin /pathto/file.sh > /log/filelog)
Jul 10 12:41:01 localhost CRON[1810]: (CRON) info (No MTA installed, discarding output)
Jul 10 12:42:01 localhost CRON[1813]: (root) CMD (mylogin /pathto/file.sh > /log/filelog)

However, the script is not running. It is not doing it's work and not echoing runs to /log/filelog.

$cat /log/filelog  #shows nothing

What other steps can I take to debug this problem?

Best Answer

Specifying a username like mylogin is for the /etc/crontab file. With your command sudo crontab -e you are actually editing /var/spool/cron/crontabs/root and you should not specify a username in such a file, only in /etc/crontab.

If you have to run the command as user mylogin you have to put the line in /etc/crontab (and edit this with root privileges), or just put it in the mylogin user's crontab.

From man 5 crontab:

EXAMPLE SYSTEM CRON FILE
    The following lists the content of a regular system-wide crontab  file.
    Unlinke  a user's crontab, this file has the username field, as used by
    /etc/crontab.
Related Question