Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a script called "" and set permissions to 777. It contains the following line:

echo "It worked: $(date)" >> /home/noc/email.log

I created a cron job with the following line:

*/5 * * * * /home/noc/

The problem is that the "email.log" file never gets changed. I even set the permissions to 666. When I run the script manually, it works perfectly.

The cron job is running according to the "/var/log/cron.log" file.

Can someone point me into the right direction as to what might be going wrong? This is a minimal virtual machine install of Ubuntu Server 9.04 with cron installed via apt-get.

*UPDATE: I made a very stupid mistake. I named my script "". I wasn't until I installed some email services and got the following error email from Cron that I discover my mistake.*

/bin/sh: /home/noc/ not found

I changed the name of the file, and it works now.

share|improve this question
isn't this more like.. serverfault question? – codingbear Aug 4 '09 at 4:04
Users use cron. – Richard Hoskins Aug 4 '09 at 4:08
can you provide output of crontab -l ? – John T Aug 4 '09 at 4:09
crontab -l outputs the same line in the original question. – Joseph Aug 4 '09 at 4:17
Does /etc/cron.allow exist? – Richard Hoskins Aug 4 '09 at 4:38
up vote 6 down vote accepted

Lots of potential things off the top of my head.

Are you sure the crontab entry is really pointing at your script? For example, if you want to run a script such as ~noc/bin/, but have an entry like /home/noc/bin/script (ie a subtle typo) then of course it won't work. I usually check my crontab entries by copying the command out of crontab with my mouse, then pasting it into a command prompt, just to be 100% sure that it is going to run what I want it to.

Does your script contain only the indicated line? Usually you have to include something like:

#!/bin/bash the top of your script to get it to work.

If it is more complicated than the single line, are you sure the programming logic will permit it to run that particular line?

Try reducing your script to

echo "Bing!" >> /tmp/cronjob see what happens. If that works, you have a programming issue in your cron script. If it fails, you have a cron issue.

Is the 'noc' user the one running the script? If not, are you sure that the user running the cron script has read/write access through /home/noc to the email.log file?

Where is the error email from the user running the cronjob going? Is an error email being generated, and then getting sent somewhere you are not expecting or maybe getting dumped altogether? Try a cronjob of

echo "Bing!"

...and then try to figure out where the email that is generated goes.

Are cron.deny and/or cron.allow in play? If /etc/cron.allow does exist, then the user noc must be listed in it; if /etc/cron.deny exists. the user noc must not be listed in it. On RedHat, if neither cron.allow nor cron.deny exist, then ONLY the root user will be permitted to use cron.

share|improve this answer
I reduced my script and nothing happens still. The noc user should be the only user running the script as it is the only account. I don't have email services installed on this server. – Joseph Aug 4 '09 at 4:30
Erm... does ubunto use cron.allow and cron.deny? – David Mackintosh Aug 4 '09 at 18:23
OK, saw your update, glad you got it figured out. – David Mackintosh Aug 4 '09 at 18:29

Cron runs with limited environment variables set, especially your $PATH. Try putting the full path to any binaries. So /home/noc/ should be:

/bin/echo "It worked: $(date)" >> /home/noc/email.log

Also, what does */5 do at the beginning of your script? */5 runs once every five minutes, 5 runs once ’5 minutes past the hour every hour.

5    *   *   *    * /home/noc/
#*   *   *   *    *  command to be executed
#-   -   -   -    -
#|   |   |   |    |
#|   |   |   |    +----- day of week (0 - 6) (Sunday=0)
#|   |   |   +------- month (1 - 12)
#|   |   +--------- day of month (1 - 31)
#|   +----------- hour (0 - 23)
#+------------- min (0 - 59)

Finally, did you edit & save the crontab with the following command:

crontab -e

... where your editor is chosen by the environment variable $EDITOR?

share|improve this answer
*/5 runs it every 5 minutes. having just 5 will run it once every hour at 5 minutes past the hour. – pgs Aug 4 '09 at 4:37
Adding the full path did not change anything. I created the contrab with "crontab -e". The editor is nano. – Joseph Aug 4 '09 at 5:08
echo "It worked: $(date)" >> /home/noc/email.log

Does /home/noc/email.log exist before you run the script? Is it writable by the user running the cron job? What happens if you create it beforehand? e.g.

touch /home/noc/email.log
chmod 666 /home/noc/email.log
share|improve this answer
No. Yes. Same thing. – Joseph Aug 4 '09 at 5:05

If you have any doubts about your script, put the line below at the top of the script:

 #!/bin/bash -x

(if you don't use this shell, just put the good one)

Starting up the subshell with the -x (eXplicit) option, which will run the entire script in debug mode. Traces of each command plus its arguments are printed to standard output after the commands have been expanded but before they are executed.

share|improve this answer

You must log in to answer this question.

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