Ok, So I've made my script, I dropped it in
/etc/cron.hourly then I
chmod 777 the file but it won't run (automatically). If I manually run it, it works fine. Do I need to do anything else?
Why not using crontab ( /etc/crontab ) and use */1 in the hour field. I have used this to run a script every 5 min and it works well:
Entries in cron.hourly are run by the run-parts mechanism (man run-parts for more info). And run-parts is choosy about what filenames it considers valid.
For example, giving your script an extension will make it invalid and result in the job not being run.
When adding a job to /etc/cron.hourly ( or .daily, .weekly, etc), always test afterwards that run-parts will actually run it by issuing the command:
What was the name of your script?
Your problem is probably down to the overly open permissions, which allows anybody to edit your file. Try
Looking in the cron entries in your syslog output should confirm this.
When you run
is this task on the list?
if not, add it
add this line
if it is in this list, try to add the path of programing language to the top of your script
This 2 things always solved my problems :)
DaithiF's answer should be the right answer.
Also, my script didn't have ''''#! /bin/bash '''' in the first line. Even though the script can be executed in command line (bash), the run-part rejected it saying "Exec format error".
So changing the file name from xxx.sh to xxx and adding the '#! /bin/bash' into first line enable my script running hourly.