[ubuntu-za] cron tutorial or Ubuntu 7.04

William Kinghorn williamk at dut.ac.za
Fri Aug 17 10:49:52 BST 2007


Thanks, nice and simple explanation

William

>>> jason at freespeechpub.co.za 08/17/07 10:21 AM >>>
On Fri, 2007-08-17 at 09:20 +0200, Herman Gouws wrote:
> >On Friday 17 August 2007 08:00:35 William Kinghorn wrote:
> >> Hi Jason,
> >>
> >> I am trying to run a debmirror script to update my mirror.
> >>
> >> I am wanting to run the script as root at midnight everyday.
> 
> >crontab -e
> >59 * * * * /usr/scripts/mirror_ubuntu.sh
> 
> >also see 
> 
> >man 5 crontab
> 
> Shouldn't that be 59 23 * * * /usr/scripts/mirror_ubuntu.sh ?
> 
> As written above the script would run once per hour.
> 
> Also, to add it to root's crontab, use 
> 
> sudo crontab -e
> 

And for a little further explanation no crontab for William's (and
others who don't know) sake:

The crontab is a Linux method of running applications and scripts at
regular intervals. It's user-specific, so each user on the system can
have his or her own crontabs. In the above example with sudo, Herman is
creating a root crontab which will run the applications he's calling as
root. Leave off the sudo to run the applications from your own account.

You can use the following commands for crontab:
crontab -e 
Edits the crontab file

crontab -l
Lists all the crontabs

crontab -u jason -e
Edit Jason's crontab if jason is not the current user (of course you
need permission to do so).

The formatting looks quite complex but is easy when you get your head
around it, and very powerful.

The format is:
minute hour "day of month" month "day of week" command

So to run the command at 11:59pm as above, you put in:
59 23 * * * /path/to/my_script

* means "every", so it's every day of the month, every month, and every
day of the week. Be warned: * * * * * means "run this command every
second". 

You can also use commas to list multiple times, just don't put in any
spaces. So to run the same command at 11:59am AND 11:59pm you could do:
59 11,23 * * * /path/to/my_script

Hyphens give the script a range. To run the script only on week-days,
you could use:
59 11,23 * * 1-5 /path/to/my_script
(For day of week, the values are 0 to 6 where 0 is Sunday)

To run a command on the 1st and 29th of January, February and March at
midnight exactly:
0 0 1,29 1,2,3 * /path/to/myscript
(Day of month values are 1-31, month values are 1-12)

Hope that helps.

J


-- 
ubuntu-za mailing list
ubuntu-za at lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-za




More information about the ubuntu-za mailing list