Posted by: Joey on: August 30, 2006
It seems that several people have had trouble creating cron jobs in Ubuntu. Here is a method I found that works for me. It requires sudo access.
The only thing you’ll need is cron and a good text editor (like nano), both of which are in the default Ubuntu install.
Create a file with your job(s) in it and save it with any filename (e.g. crontab_file). Put each job on it’s own line like so:
* * * * * sh /home/userbob/script1 * * * * * sh /home/userbob/script2
Next run crontab with sudo on the file you just created. Be sure to select your username with the -u option:
sudo crontab -u userbob crontab_file
And that’s it. Pretty simple, huh? I hope this helps you out. Check out the crontab page at Wikipedia for help with formatting your own cron jobs.
Just to clarify, you need to check out the proper notation for crontab to determine how to write your own cron jobs and make them run when you want them to.
Another clarification. You must create a file with each cron job on a separate line and then run crontab on it to make it work. You should do this as a user using the sudo command. Don’t be running scripts as root. Don’t be doing work as root. Don’t do anything as root unless you have no other choice. Just forget that root even exists. Your life will be better.
Every minute of every day, not every second – sorry.
Doesn’t work for me. And I don’t undersand why.
I saved: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * sh /etc/init.d/firewall in /home/firewall/fw
Then: crontab -u root /home/firewall/fw
I don’t understand what’s wrong :(
try this
*/5 * * * * sh /etc/init.d
February 21, 2008 at 9:39 pm UTC
A good quick tip, but I would encourage everyone to check the crontab manpage (man crontab). The ‘* * * * *’ will cause the command to be run every second of every day, which is inappropriate and unnecessary for most tasks – and will flood some system logs with cron messages. Have a look at what each * represents and tailor your solution to your problem.