Solved

setting a one off cron job in crontab

Posted on 2006-06-23
8
395 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows 7 starter missing password 21 100
winscp where are logs stored 3 76
HOw To Install Docker on VMware Workstation 19 347
Redhat upgrade 1 48
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

726 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