Solved

setting a one off cron job in crontab

Posted on 2006-06-23
8
390 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
 
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now