4

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?

  • 1
    "info (No MTA installed, discarding output)" ... was probably the error message that'd explain why your script isn't running. You could install one (possibly a very trivial one, or even just a /usr/sbin/sendmail script...) – derobert Jul 10 '14 at 17:14
  • 1
    "mylogin" what is this ?i assume if you remove this it will be executed .. and it is always better to do log inside the script and cron entries to redirect to /dev/nul – klerk Jul 10 '14 at 17:22
  • @klerk mylogin is my username! just not posting that online. I did not know that about logging and will do so in the future. But problem still remains – bernie2436 Jul 10 '14 at 17:36
  • 3
    you dont need username! if you edit crontab with some user it is writen in /var/spool/cron/<username> if script is ok it will work without mylogin! – klerk Jul 10 '14 at 17:45
7

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.