?
Solved

setting a one off cron job in crontab

Posted on 2006-06-23
8
Medium Priority
?
402 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:joe1976
8 Comments
 
LVL 16

Expert Comment

by:xDamox
ID: 16967872
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
0
 
LVL 16

Expert Comment

by:xDamox
ID: 16967884
Opps I should of put:

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

Author Comment

by:joe1976
ID: 16967932
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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Expert Comment

by:JulieBouillon
ID: 16968005
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, ...)
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16968118
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.

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

0
 
LVL 22

Accepted Solution

by:
pjedmond earned 2000 total points
ID: 16968174
Best I read the question properly!

at -f mycommand 19:45 25/06/06

Where the file mycommand is:

---------------8X-----------------
/opt/utils/sendMesg.sh
---------------8X-----------------

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

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. I guess if you don't have access to the 'at' command due to /etc/at.allow permission not allowing you to use it then your approach is fine. Just remember to remove the crontab entry after you've used it:)

(   (()
(`-' _\
 ''  ''
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 16968194
>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.

(   (()
(`-' _\
 ''  ''
0
 
LVL 16

Expert Comment

by:xDamox
ID: 16968313
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)

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Fine Tune your automatic Updates for Ubuntu / Debian
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question