Cron job executed at wrong time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Cron job executed at wrong time
# 1  
Old 12-07-2012
Apple Cron job executed at wrong time

Dear *nix users.

I'm on Mac OS 10.6 / Terminal and try to use crontab to schedule two scripts every 30 minutes and every 41 minutes.

I followed the man instructions and created / installed a crontab file for the current user:crontab -e

with the following content
Code:
*/30 * * * * /usr/local/bin/Script1.sh
*/41 * * * * /usr/local/bin/Script2.sh

Here is the problem: Script1 runs every half hour and Script2 runs every 41th minute of each hour. But both scripts run at each full hour. I don't understand why. What's going wrong?

Best wishes, M.

Last edited by Scott; 12-07-2012 at 07:04 AM.. Reason: Code tags
# 2  
Old 12-07-2012
Step values (like your /41) don't cross hourly (or daily, monthly, etc.) boundaries, so come the next hour it starts over. So there's often little point in having a step value greater than 30 which also isn't nicely divisible into 60 (for minutes) if you want a job to run at a fixed interval.

For example, using /25

Code:
$ crontab -l
*/25 * * * * /bin/date >> /tmp/date.txt

$ tail -f /tmp/date.txt 
Fri Dec  7 12:25:00 CET 2012
Fri Dec  7 12:50:00 CET 2012
Fri Dec  7 13:00:00 CET 2012
Fri Dec  7 13:25:00 CET 2012


Last edited by Scott; 12-07-2012 at 08:29 AM.. Reason: Added example
# 3  
Old 12-07-2012
Quote:
Step values .. don't cross hourly .. boundaries
Ah, this is the problem. I've just assumed: every 41 minutes is what it says.
I try to figure out a better scheduling approach. Thank you Scott.
# 4  
Old 12-07-2012
For odd times like this, what is sometimes done is running the job more often than needed, and having the job check the time itself. If it's not what you wanted, quit early.
# 5  
Old 12-07-2012
Thank you for your hint Corona688.
This time, however, I content myself with easy solution.
Not perfect, but acceptable
Code:
0,30 * * * * /usr/local/bin/Script1.sh
15,45 * * * * /usr/local/bin/Script2.sh

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to detect and fix why crontab job is not executed?

I have set several cron jobs. I recently added a new cron job that copies a file of last day from another server and is executed each day (for example at 04:00 am) but when I check next day the file hasn't been copied. I'm working in GNU/Linux CentOS (2.6.32) system. The files that I need to... (23 Replies)
Discussion started by: Ophiuchus
23 Replies

2. UNIX for Beginners Questions & Answers

/etc/cron.daily script is not being executed

Hi All I have created a file in /etc/cron.daily on redhat linux 7.3 version host called applicationscript cat applictaionscript #!/bin/bash /prod/data/routine.sh cat /prod/data/routine.sh #!/bin/bash #details regular=/prod/data/jboss/logs backup=/prod/data/logs #echo "Moving logs"... (3 Replies)
Discussion started by: anil529
3 Replies

3. Shell Programming and Scripting

Script executed by Cron or commandline

Hello all, I have a question regarding the difference betwen cron and command line. What I would like to do is to print a statement into a logfile if a script has been executed from cron or from command line. It should be as: #!/bin/bash if <Check if this script has been... (3 Replies)
Discussion started by: API
3 Replies

4. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

5. Shell Programming and Scripting

crontab job not executed with variables

Hi, I am trying to execute a script (for once) during the booting time in Ubuntu system. However, the result is only showing the strings without without the variables. Here is the script: MgrIp=$(ec2-describe-instances --filter tag:Name=Mgr --filter instance-state-name=running | egrep... (4 Replies)
Discussion started by: turki_00
4 Replies

6. UNIX for Dummies Questions & Answers

Setup a cron job and specified the start and end time

Hi guys, How can I specify the start and end time of a cron job. And my start time and end time are specified by minutes. For example, I want to set up a cron runs every 3 minutes from 18:40 to midnight. How can i do this please? Many thanks Best regards, Clu (4 Replies)
Discussion started by: clu
4 Replies

7. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

8. UNIX for Advanced & Expert Users

Completion time of a cron job ?

how can we identify the task completion time which was initiated by CRON. we have 1000 of jobs whihc are runing from cron so it is not feasable to edit every cron entry or every script to add the respective code to find teh completion time. Can some one please provide a inut to find the task... (3 Replies)
Discussion started by: NIMISH AGARWAL
3 Replies

9. Shell Programming and Scripting

Script errors out only when its executed via job

I wrote a script to shutdown the oracle database. The script works fine when I manually run the script. However, when i schedule a job, i get the following error. Shutting Down cmismart .................... ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist SVR4... (6 Replies)
Discussion started by: mrx1350
6 Replies

10. Shell Programming and Scripting

ant not being executed as cron job

i have a script that uses an ant build.xml and its targets to pull a project from a cvs server, attempt to build the project, and then email me the results. When I run the script (either @ CLI or as a cron job) while I am logged in, everything works fine. However, if the script is set up to run... (5 Replies)
Discussion started by: kingfinny
5 Replies
Login or Register to Ask a Question