PDA

View Full Version : crontab



flyingsliverfin
October 3rd, 2010, 08:00 PM
how would i add an entry to crontab if i just want the script to be run once every day at any time (but only once a day!) would it be:

* * * * * /x/x/x/x

dwhitney67
October 3rd, 2010, 08:13 PM
Your example runs the script every minute.

To run it once per day, at a designated hour, modify the second field (ie the second *) with a hour number ranging from 0 to 23.


* 14 * * * /path/to/my/script

Above, the script will be run at 14:00 (2pm) every day.

SeijiSensei
October 3rd, 2010, 09:15 PM
I'd put a zero in the first column to get 14:00 like this:

0 14 * * * /path/to/my/script

I think that

* 14 * * * /path/to/my/script

will run once every minute from 14:00 to 14:59.

flyingsliverfin
October 4th, 2010, 02:51 AM
right but my desktop isnt always on and im not sure when i'll be on. It's different day to day. is there a way to get it to run the script once a day as soon as the computer turns on?

spjackson
October 4th, 2010, 09:03 AM
right but my desktop isnt always on and im not sure when i'll be on. It's different day to day. is there a way to get it to run the script once a day as soon as the computer turns on?
Well, you can get a command to run at reboot


@reboot /x/x/x/x
(See "man 5 crontab".) However, that wouldn't quite do what you want because
a) It would run twice if you booted twice in one day.
b) If your computer stayed on for over 24 hours then it would not run on the 2nd day.

You could put something in your script to check whether it has already been run today to cater for a). You could also include an "@daily" entry to cater for b).

dwhitney67
October 4th, 2010, 09:56 AM
I'd put a zero in the first column to get 14:00 like this:

0 14 * * * /path/to/my/script

I think that

* 14 * * * /path/to/my/script

will run once every minute from 14:00 to 14:59.

Thanks for catching my mistake.

flyingsliverfin
October 4th, 2010, 10:47 PM
i actually usually put my desktop to suspend not shutdown. is there a @___ for waking up?

spjackson
October 4th, 2010, 11:05 PM
i actually usually put my desktop to suspend not shutdown. is there a @___ for waking up?
Did you read the bit that said 'See "man 5 crontab"'? Let me see... no there isn't.

However, a quick Google tells me any jobs that were due to run while suspended will run on wakeup. So, just schedule it for any time you like. (Note that, jobs that were skipped while the system was down, rather than suspended, are *not* invoked at boot time.)

flyingsliverfin
October 5th, 2010, 01:03 AM
so it makes up the things it missed. thta should be good enough for my purposes

jakupl
October 5th, 2010, 01:13 AM
Have a look at anacron. Anacron is probably more suitable for you.

http://en.wikipedia.org/wiki/Anacron

flyingsliverfin
October 5th, 2010, 02:15 AM
so for anacron i edited the /etc/anacrontab and added
1 5 test /x/x/x

that will execute it once a day at a 5 min after the computer turns on?