cancel
Showing results for 
Search instead for 
Did you mean: 

Cron batch job question

SOLVED
Go to solution
Jorge Cocomess
Super Advisor

Cron batch job question

Hi,

I have this cron job that runs every 15 minutes. Now, I would like to have it run 4 times a day, starting at 6:30 AM. How would I change the time format in the cron job?

Thank you in advance.

Jorge
12 REPLIES
Court Campbell
Honored Contributor

Re: Cron batch job question

a simple solution would be to add 4 separate cron entries in /etc/crontab. set each of them to run at the specified times that you want.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
John Poff
Honored Contributor
Solution

Re: Cron batch job question

Hi,

One way to do it is:

30 6,12,18,00 * * * /some/batch/script

which would run it at 6:30am, 12:30pm, 6:30pm, and 12:30am.

Try a 'man 5 crontab' to arrive at true cron job enlightenment.

JP

Court Campbell
Honored Contributor

Re: Cron batch job question

Use John's suggestion. It is much cleaner. I have no excuse for not suggesting that in the first place. but as I always say, there is more that one way to do it.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
John Poff
Honored Contributor

Re: Cron batch job question

Court,

I made my suggestion based on the fact that I'm too old and too lazy to type in four lines. :)

JP

Jorge Cocomess
Super Advisor

Re: Cron batch job question

Great. I will give that try.

Thanks for your help.

Jorge
Manuel Wolfshant
Trusted Contributor

Re: Cron batch job question

For what is worth,cron knows about steps, so if you have a regular interval between the runs, you could use
30 6/6 * * * /some/batch/script

Which translates into start at 6:30 (the first 6 in the hours field plus the minutes field) and run after every 6hrs (24hrs/4= 6 hrs => second 6 in the hours field)
Stuart Browne
Honored Contributor

Re: Cron batch job question

Just a caution for the previous post.

This will work fine on the cron daemon used on most Linux distributions for the past 10 years or so (go Vixie crond!); just be careful when you use other OS's. Some of them don't have a cron daemon as flexable.

Other things to note are things like '/etc/crontab', and '/etc/cron.d/' on top of user crontab's (modified using '/usr/bin/crontab -e'.

So very very useful, especially for distributing jobs to other servers.. ;)
One long-haired git at your service...
Jorge Cocomess
Super Advisor

Re: Cron batch job question

Hi,

I made the changes like John had recommended. However, the cron job is not running though. I can't seem to see any syntax errors. Although, is there a space after the comma (30 06,10,13,19, ei)>>>

Please help.

Thanks,
Jorge
John Poff
Honored Contributor

Re: Cron batch job question

Try it without any spaces in the list for the hours, and try redirecting output to a file:

30 6,12,18,00 * * * /some/batch/script >>/var/tmp/script.out 2>&1

Also, you might want to check permissions and ownership of your script, as well as setting the PATH explicitly inside of the script.

JP
Rob Leadbeater
Honored Contributor

Re: Cron batch job question

You might also want to check cron's log for errors, which is (usually) in /var/log/cron

Regards,

Rob

Court Campbell
Honored Contributor

Re: Cron batch job question

see if /etc/cron.allow exists. if it does make sure the account running the job is located in the file. otherwise see if the account is listed in /etc/cron.deny and remove it from that file. Just a hunch.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: Cron batch job question

OK, i am an idiot. You were are already running the jobs successfully. Ignore my last post.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"