I installed cron with sudo apt-get install cron, started it as root and confirmed that it is running with
ps -ef
I then created a simple script with the following contents:
touch /home/username/cron-test.txt
I made this script file executable and put it into
mv cron-test.sh /etc/cron.hourly
For some reason though, it does not get executed and the file is not being created. I tried running it manually and it works.
I also tried other cron scripts and they do not seem work. Did I miss something or am I using cron incorrectly?
My system is Ubuntu 10.10 and my hoster has stripped it down so it came with only a few processes installed (not even cron).
Try adding
#! /bin/sh
as the first line of your script and removing the extension, so that the name is/etc/cron.hourly/cron-test
I remember reading somewhere that cron will not run files with an extension, because it uses runparts when
/ect/crontab
has the following contents:The above is the content of my
/etc/crontab
on Ubuntu 10.04, with cron installed (I have not edited this file)Since the
/etc/crontab
file usesrun-parts
, filename are very restrictive as per (Thanks Matteo):Here's a quote from the run-parts man page:
The thing is, you've included a '.' in your filename (just before the 'txt'). That period doesn't match the filename pattern that run-parts uses to find scripts.
Remember that file extensions are NOT part of the filesystem! Any file extensions you put on are simply part of the filename, and so when the rules say 'filename', that includes the period and the extensions.
Further,
Which means that you MUST put in the #!/bin/bash in order for your script to be executed.