Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

up vote 4 down vote accepted

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:

# m h dom mon dow user  command
* */1  * * *   user    command
share|improve this answer
    
I'll give it ago and let you know thanks! –  Switchkick Oct 21 '10 at 0:13
3  
Using cron.daily and friends works a bit better if the machine is not running all the time, because anacron tries to approximate the right schedule whereas plain cron will just not run them if the machine is not on all night. For hourly jobs this probably doesn't matter so much. –  poolie Dec 2 '10 at 0:20
3  
I really appreciate the next answer, as it addresses the problem with cron.hourly, rather than finding a workaround. –  tishma Jan 24 at 14:24

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: run-parts --test /etc/cron.hourly

What was the name of your script?

share|improve this answer
    
There are two: cerebro_random_response.sh and Cerebro Temperature.sh no good? –  Switchkick May 14 '11 at 0:41
5  
correct, no good :) [a-zA-Z0-9_-] are the valid characters, so the '.' makes it invalid. This is what i meant above by 'giving your script an extension will make it invalid' –  DaithiF May 19 '11 at 16:43
    
oMG, This just saved a huge headache. THANK YOU! giving your script an extension will make it invalid and result in the job not being run –  exabrial Dec 5 '13 at 22:16
    
Oh shit, giving an extension make it unable to work ? oh - shit - !! –  Cyril N. Jun 23 at 10:29

Your problem is probably down to the overly open permissions, which allows anybody to edit your file. Try 755 instead.

Looking in the cron entries in your syslog output should confirm this.

share|improve this answer
    
This was a no go Joe, thanks anyway. –  Switchkick Oct 21 '10 at 0:13

When you run

crontab -l

is this task on the list?

if not, add it

crontab -e

add this line

0 * * * * yourScript

if it is in this list, try to add the path of programing language to the top of your script

Example:

bash: #!/bin/bash

This 2 things always solved my problems :)

share|improve this answer
    
Done it all and the script is good, it works like a charm. It's in the crontab list too but no hourly task runs. Thanks anyway :( –  Switchkick Oct 20 '10 at 8:17

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.

share|improve this answer

Your Answer

 
discard

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.