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
firefox www.superuser.com
Into a file test.sh 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 91.189.94.4 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.
edit2:
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
/etc/cron.hourly/test
/etc/cron.hourly/test2
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
firefox www.stackoverflow.com
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)
sandpitdirectory in root's home directory where the cronjob can write itsbar.txtfile? – Kusalananda Nov 1 '11 at 11:57#!/usr/bin/env shrather than#!/bin/sh? It's far more likely thatenvisn't in/usr/bin/than thatshisn't in/bin. – Keith Thompson Nov 8 '11 at 1:44