Link to home
Start Free TrialLog in
Avatar of joe1976
joe1976

asked on

setting a one off cron job in crontab

Hi

I want to set up a cron job to run once at 7.45pm on Sunday. Is this setting correct?

45 19 25 6 0 /opt/utils/sendMesg.sh

Thanks

Joe
Avatar of xDamox
xDamox
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,

The above will run at 7:45PM on the 25 of the month June you could change it to the following:

45  19  0  0  0  /opt/utils/sendMesg.sh

The above should run at 7:45PM every sunday
Opps I should of put:

45  19  *  *  0  /opt/utils/sendMesg.sh
Avatar of joe1976
joe1976

ASKER

Thanks for the quick reply. I'm sure I read somewhere that the 3 and 5th fields are OR'd, so would your solution not run tomorrow night at 7.45pm as well?
If you want to run the job only one time, you should use the "at" command.
Only use cron if you want your job to run more than once (eg. each 25th of month, each day at 1 am, ...)
As mentioned by JulieBouillon, you should use 'at' if this is a one off command. cron is for repeated tasks.

at -f mytask 18:30

Will run the tasks in the file "mytask" at 18:30

Tasks need to be 1 per line in the mytask file.

You will probably need to create the file:

/etc/at.allow

and add your username to it if you want to run 'at' as any user other than root.

man at

is worth a read if you wish to be able to examine tasks in the 'at' queue.

(   (()
(`-' _\
 ''  ''

ASKER CERTIFIED SOLUTION
Avatar of pjedmond
pjedmond
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>in the crontab will sendMesg.sh this year at 19:45 on 25 Jun, and also 19:45 on 25 Jun next year, the year after and so on.

Ooops - slight mistake -- It will only run in a year where 25 Jun is a Sunday! Change the 0 to a * for every year!

http://www.adminschoice.com/docs/crontab.htm#Crontab%20file

for crontab syntax.

(   (()
(`-' _\
 ''  ''
Hi joel1976,

*     *   *   *    *  command to be executed
-     -    -    -    -
|     |     |     |     |
|     |     |     |     +----- day of week (0 - 6) (Sunday=0)
|     |     |     +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)