Need help regarding cronjob scheduling


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Need help regarding cronjob scheduling
# 1  
Old 09-30-2014
Need help regarding cronjob scheduling

Hello All,

I have three requirements to schedule three shell scripts in crontab.
Could you please help me in this:
1) To schedule a shell script every 5mins interval every day between 10PM to 10:30PM
2) To schedule a shell script every 10min interval every day between 9AM to 10AM.
3) To schedule a shell script every day 10min interval every day between 7:30AM to 8:30AM.

Thanks in advcance.
# 2  
Old 09-30-2014
Quote:
Originally Posted by abhi_123
Hello All,

I have three requirements to schedule three shell scripts in crontab.
Could you please help me in this:
1) To schedule a shell script every 5mins interval every day between 10PM to 10:30PM
2) To schedule a shell script every 10min interval every day between 9AM to 10AM.
3) To schedule a shell script every day 10min interval every day between 7:30AM to 8:30AM.

Thanks in advcance.
Hello abhi_123,

Following may help you. (Not tested though)

Quote:
1) To schedule a shell script every 5mins interval every day between 10PM to 10:30PM

00-30/5 22 * * * /test/singh/test.ksh


Quote:
2) To schedule a shell script every 10min interval every day between 9AM to 10AM.

*/10 9-10 * * * /test/singh/test.ksh


Quote:
3) To schedule a shell script every day 10min interval every day between 7:30AM to 8:30AM.

30/10 7-8 * * * /test/singh/test.ksh



Thanks,
R. Singh
# 3  
Old 09-30-2014
Thanks a lot R.Singh.

Could you also please explain me the below meaning:
1) 00-30/5 22 --> 30divided by 5? and 22 means..?
2) 30/10 ?
Thanks again.
# 4  
Old 09-30-2014
Quote:
Originally Posted by abhi_123
Thanks a lot R.Singh.

Could you also please explain me the below meaning:
1) 00-30/5 22 --> 30divided by 5? and 22 means..?
2) 30/10 ?
Thanks again.
Hello abhi_123,

Following may help you in same, also you can get more information from man cron too.

1st: 00-30/5 22 * * * /test/singh/test.ksh22 shows script should run from 10:00 PM 00-30to 10:30 PM within every 5 mins. Here /5 shows every 5 mins.

2nd: */10 9-10 * * * /test/singh/test.ksh 9-10 shows from 09:00 AM to 10:00 AM, */10 means every 10 mins.

3rd: 30/10 7-8 * * * /test/singh/test.ksh 7-8 shows fr 07:00 AM to 08:00 AM, 30/10 means starts from 30th min and run every 10 mins.

Hope this helps.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 09-30-2014
Note that not all OSs support using / (AIX springs to mind). In that case you'll need to specify all the possible values in a list, e.g.
Code:
00,05,10,15,20,25,30 22 * * * test.ksh

# 6  
Old 09-30-2014
Quote:
Originally Posted by abhi_123
Hello All,

I have three requirements to schedule three shell scripts in crontab.
Could you please help me in this:
1) To schedule a shell script every 5mins interval every day between 10PM to 10:30PM
2) To schedule a shell script every 10min interval every day between 9AM to 10AM.
3) To schedule a shell script every day 10min interval every day between 7:30AM to 8:30AM.

Thanks in advcance.
Some of RavinderSingh13's suggestions would work on some Linux and UNIX systems, but would not work on others; some would be accepted by some system, but would not trigger at the requested times. The following should work with any version of cron assuming that when you say between you mean to include the end points:
  1. 0,5,10,15,20,25,30 22 * * * /path/to/your/script
  2. 0,10,20,30,40,50 9 * * * /path/to/your/script
    0 10 * * * /path/to/your/script
  3. 30,40,50 7 * * * /path/to/your/script
    0,10,20,30 8 * * * /path/to/your/script
If you don't want to include the end points:
  1. 5,10,15,20,25 22 * * * /path/to/your/script
  2. 10,20,30,40,50 9 * * * /path/to/your/script
  3. 40,50 7 * * * /path/to/your/script
    0,10,20 8 * * * /path/to/your/script

Last edited by Don Cragun; 09-30-2014 at 08:47 AM.. Reason: Try to get around list formatting bug.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 7  
Old 09-30-2014
As always with cron scripts: watch out for Cron Problem Number One.

In addition i strongly suggest to add redirections to your crontab entries:

Code:
0,5,10,15,20,25,30 22 * * * /path/to/your/script >/dev/null 2>/dev/null

Otherwise whatever your script produces as output would be sent to you via mail. If you want to preserve any output replace /dev/null with the name of a log file but never have any entry without such a redirection.

I hope this helps.

bakunin

/PS: i prefer using this style of redirection because it is not dependent on order. The following to lines do the same:
Code:
0,5,10,15,20,25,30 22 * * * /path/to/your/script 1>/dev/null 2>/dev/null
0,5,10,15,20,25,30 22 * * * /path/to/your/script 2>/dev/null 1>/dev/null

whereas these two lines produce different results:
Code:
0,5,10,15,20,25,30 22 * * * /path/to/your/script >/dev/null 2>&1
0,5,10,15,20,25,30 22 * * * /path/to/your/script 2>&1 >/dev/null

bakunin
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script scheduling in cronjob

Hi, I have developed a file deletion script and scheduled it in cronjob to run daily at 5:00 AM. But the script is not running automatically any day. However when I run the script manually at any time, it runs successfully. This is how the cron looks like : 0 5 * * *... (5 Replies)
Discussion started by: jhilmil
5 Replies

2. Shell Programming and Scripting

Scheduling scheduling !!!

Hi, i have 10 sh scripts. All are running in parallel using cron tab and each script gives "success" flag files once the execution is completed. and, now i have 11th script which should look for "success" flag from those 10 sh scripts. once all the 10 flag files found, 11 th script has to do... (9 Replies)
Discussion started by: nago123
9 Replies

3. Shell Programming and Scripting

Crontab scheduling

Hi all, My OS is Solaris 10. I want to schedule a job which i need to run between morining 6 to eve 6 once for every 2 hours. This is what i did. 0 6-18 * * 1-5 /monitor.sh It runs for every hour how to make it for every two hours ...... Thanks, Firestar. (1 Reply)
Discussion started by: firestar
1 Replies

4. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

5. Linux

Help with cronjob scheduling

Hi Everybody, How to schedule a job using cron that shouldn't run between working hrs 9am-5pm, while run in non working hrs every hour, every day of the month, month & week. I tried the following way, not sure I can use logical not operator(!). Please correct me if wrong or suggest other... (2 Replies)
Discussion started by: sudhirav
2 Replies

6. Programming

Time scheduling

Hello !!! i am trying to create a command scheduler (written in C). Basically i would like to do what the "at" command does , but without using "at" or "cron". I have tried using getitimer but i do not know how can i shcedule multiple commands. Any ideas ??? (2 Replies)
Discussion started by: mcnikolas
2 Replies

7. HP-UX

cron scheduling?

Hi all, i want a job to run first monday of every of month. (1 Reply)
Discussion started by: megh
1 Replies

8. Shell Programming and Scripting

script scheduling

Hi, I have a ksh scrip (x) that scans a directory and does actions when a file arrives in this directory. My question is what is the best way to schedule x? 1. Use cron tab and create a task running forever 2. Creat another ksh script (y) that runs (x) in a non-terminating loop Which... (2 Replies)
Discussion started by: GNMIKE
2 Replies

9. UNIX for Dummies Questions & Answers

scheduling

i have tried to schedule my process at a certain time using the at command : the error says bad time specification can somebody help me i used at 2300 job thanks (2 Replies)
Discussion started by: prashantuc
2 Replies

10. UNIX for Dummies Questions & Answers

regarding the scheduling of the process

Hello, I would like to schedule a command at a specific time on my system.I know that theres a file named at.alow and at.deny in my system. I can find the at.deny file but not an at.allow file . Is there anyway out or i have to go and talk to the system administrator itself , or any other way of... (1 Reply)
Discussion started by: prashantuc
1 Replies
Login or Register to Ask a Question