Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 was told that to get a cron job running hourly you simply have to put a shell script into /etc/cron.hourly

So I tried adding

#!/usr/bin/env sh

Into a file and putting it into /etc/cron.hourly/ directory. Then I chown it to root and chmod +x on it. It does as expected if I execute it directly. But it doesn't execute automatically, hourly.. what am I missing?

edit: I've changed the script to something simpler, just

#!/usr/bin/env sh
echo foo > ~/sandpit/bar.txt

Then I waited an hour , these are the last 4 lines at the end of my /var/log/syslog

Nov  1 18:45:01 wim-ubuntu ntpdate[1719]: adjust time server offset -0.149832 sec
Nov  1 18:46:27 wim-ubuntu kernel: [  106.562460] exe (2058): /proc/2058/oom_adj is deprecated, please use /proc/2058/oom_score_adj instead.
Nov  1 19:17:01 wim-ubuntu CRON[4204]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Nov  1 20:17:01 wim-ubuntu CRON[4793]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

But my file isn't being created, so I guess my cron job still isn't going.


I removed the extensions, now I have the scripts actually found by cron. But they are failing for unknown reasons (details below)

wim@wim-ubuntu:/etc/cron.hourly$ ll
total 28
drwxr-xr-x   2 root root  4096 2011-11-02 01:32 ./
drwxr-xr-x 150 root root 12288 2011-11-02 01:58 ../
-rw-r--r--   1 root root   102 2011-09-20 10:04 .placeholder
-rwxr-xr-x   1 root root    49 2011-11-01 19:00 test*
-rwxr-xr-x   1 root root    48 2011-11-01 19:23 test2*
wim@wim-ubuntu:/etc/cron.hourly$ run-parts --test /etc/cron.hourly
wim@wim-ubuntu:/etc/cron.hourly$ date
Wed Nov  2 02:25:39 EST 2011
wim@wim-ubuntu:/etc/cron.hourly$ cat test
#!/usr/bin/env sh

wim@wim-ubuntu:/etc/cron.hourly$ cat test2
#!/usr/bin/env sh
echo foo > ~/sandpit/bar.txt

wim@wim-ubuntu:/etc/cron.hourly$ tail -4 /var/log/syslog
Nov  2 02:01:33 wim-ubuntu AptDaemon: INFO: Quitting was requested
Nov  2 02:17:01 wim-ubuntu CRON[8249]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Nov  2 02:17:01 wim-ubuntu CRON[8248]: (CRON) error (grandchild #8249 failed with exit status 1)
Nov  2 02:17:01 wim-ubuntu CRON[8248]: (CRON) info (No MTA installed, discarding output)
share|improve this question
It's probably executing and failing as its a graphical program. Have you considered writing to. File instead for testing? Also, you could try your user account's personal crontab – Daniel Beck Nov 1 '11 at 8:14
Check your syslog. If the job was executed, cron logs that. – barbaz Nov 1 '11 at 8:27
Do you have a sandpit directory in root's home directory where the cronjob can write its bar.txt file? – Kusalananda Nov 1 '11 at 11:57
yes, i created the directory first – wim Nov 1 '11 at 14:31
Why are you using #!/usr/bin/env sh rather than #!/bin/sh? It's far more likely that env isn't in /usr/bin/ than that sh isn't in /bin. – Keith Thompson Nov 8 '11 at 1:44

Some versions of cron don't run scripts with file name extensions so try renaming the script (eg: mv test).

You can probably check what cron will run using this test (it doesn't actually run the files):

run-parts --test /etc/cron.hourly
share|improve this answer
it seems you were right about the extensions, my scripts are at least recognised by cron now. but they aren't running properly. if i remove the --test and use run-parts /etc/cron.hourly they seem to run ok – wim Nov 1 '11 at 15:29
up vote 1 down vote accepted

I'm still not sure why my jobs in /etc/cron.hourly don't run. But I was able to schedule them in an alternate way by adding them manually with the command crontab -e.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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