Execute crontab for every 4 hours and begin from current time


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Execute crontab for every 4 hours and begin from current time
# 1  
Old 05-30-2011
Execute crontab for every 4 hours and begin from current time

I want to add a crontab entry which should execute for every 4 hours and that 4 hours calculation should begin from the current time.

Normally if I set the crontab entry like this,

Code:
00 */4 30 05 * root date >>/tmp/cronout

The above will execute the date command for every 4 hours like 4,8,12,16,20,24 on 30th May, for example I start the crontab at 02:00:00. But if I start the crontab at 09:15:00, it should execute the crontab command after 4 hours like 13:15:00, then 17:15:00 like this.

Can any one please tell me, how to achieve this in crontab ?

Last edited by pludi; 05-30-2011 at 09:06 AM..
# 2  
Old 05-30-2011
Code:
15 */4 30 05 *   /usr/bin/date >>/tmp/cronout

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 05-31-2011
If I start the above crontab at 9:00:00, it will execute the date command at 12:15:00, but I need this should be executed at 13:15:00 !

It wont work ! Smilie

Is there any other way ?
# 4  
Old 05-31-2011
You can setup cron to run @ specific start time only and use something like this :
Code:
15 9 * * * yourjob.sh

With yourjob.sh :
Code:
INTERVAL=14400 ## 4 hours in seconds
ITT=4 ## number of iterations
i=1
while (( i <= $ITT ))
do
date & ## i used date for test, this should be yourjb
sleep $INTERVAL
i=$(expr $i + 1)
done

You shouldn't loose to much seconds Smilie and it will run 9.15, 13.15, 17.15,21.15
This User Gave Thanks to Peasant For This Post:
# 5  
Old 05-31-2011
I need to achieve this with the crontab entry itself, not using any other script.

In the crontab, I need to initialise the job to call another script for every 4 hours from the current time.

Time specified here is only for example.
# 6  
Old 05-31-2011
Don't understand what triggers the start of this recursive process.
Quote:
But if I start the crontab at 09:15:00
What would you type to cause this event?
This User Gave Thanks to methyl For This Post:
# 7  
Old 05-31-2011
@Ganeshwari, why do you have to use cron?

Don't use cron. It wasn't designed for that.

Just start a job, perhaps a wrapper, that runs your script every 4 hours.
This User Gave Thanks to purdym For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File write begin/end, recording time

Hello all, How can I find out the start and end of the writing file in the directory or recording time for writing file? I have a directory where small ~ 1*MB temporary files are written. After the end of the record, they are retrieved and erased. I can only find out that the files are... (4 Replies)
Discussion started by: mrAibo
4 Replies

2. Shell Programming and Scripting

Log search and mail it if the log is updated before 24 hours from the current time

Hi , We have around 22 logs , each has different entries. I have to automate this using shell script. The ideas which am sharing is given below 1) We use only TAIL -100 <location and name of the log> Command to check the logs. 2) We want to check whether the log was updated before 24... (13 Replies)
Discussion started by: Kalaihari
13 Replies

3. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

4. HP-UX

Crontab do not run on PM hours

Hi All I have a problem, I wonder if you can help me sort it out: I have the following entry in the cron: 00 1,13 * * * /home/report/opn_amt_gestores_credito.ksh > opn_amt_gestores_credito.log But the entry only runs at 01:07 I have stopped the cron deamon, and started, but it still... (39 Replies)
Discussion started by: fretagi
39 Replies

5. AIX

crontab 1 hour off from current time

This is a new one on me. We upgraded a system from AIX 5.3 TL 7 to 6.1 TL 7 yesterday. The app people notified us that their cron jobs weren't running at the right time. So I made a test cron entry and here's what I've found: # crontab -l * * * * * /usr/bin/date > /tmp/test.log 2>&1 # cat... (2 Replies)
Discussion started by: homeyjoe
2 Replies

6. Shell Programming and Scripting

Adding hours to current date

Hi, any idea how to add hours to current date in unix. thanks in advance (9 Replies)
Discussion started by: Abhijeet_Atti
9 Replies

7. Shell Programming and Scripting

Reading Hours and Minutes from file and comparing with current

Hi, Time till when the application should run is indicated in a file. First line is hour and second line is minute. file: 10 55 Means my application should run till 10:55. Now in a shell script, i am trying to make that logic but with no luck. min=`tail -n 1 /file_with_time`... (1 Reply)
Discussion started by: SGD
1 Replies

8. Solaris

How to define every 5 hours in Crontab

Hi Experts, I want to run a script which will move the files from particular directory to another backup directory After EVERY 5 hour. How can I put it in crontab- 5 hours!!! * * * * /home/movefilescritp.sh //purple (8 Replies)
Discussion started by: thepurple
8 Replies

9. UNIX for Dummies Questions & Answers

crontab every 2 minutes, 24 hours and once a week

can someone please check my answers for the crontabs I am making 1. how would I set up a crontab tab executes every 2 minutes each and every day of the week? answer: 2 * * * * /path/to/file.pl <-- is this correct? 2. how would I set up a crontab that executes every 24 hours at 2am?... (6 Replies)
Discussion started by: Bobafart
6 Replies

10. UNIX for Dummies Questions & Answers

AT command to batch execute every x hours

I want to schedule a batch job (SQL)to run every 6 hours in Unix and the AT command syntax does not seem to cover this. I have created a file ncd_rpt in the directory report and have given the command in this file. at -f /report/ncd_rpt 1:00 am tomorrow I schedule this by running sh... (1 Reply)
Discussion started by: naveen79
1 Replies
Login or Register to Ask a Question