How to Set crontab for 4th and 25th of every month?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to Set crontab for 4th and 25th of every month?
# 8  
Old 04-02-2014
Thanks!

it means it will work on for 11th and 12th month also right..

if [ "$month" -le "10" ] ; then
pmonth=0`echo $month`
else
pmonth=`echo $month`
# 9  
Old 04-02-2014
@ajju,
when value of
Code:
$m

is 04(4th month), then value of
Code:
$month

will be 3 with following expression.
Code:
month=`expr "$m" - 1`

Below codes are used for obtaining output as 03(as per your requirement) . And used from 2nd month to 10th month ,
Code:
if [ "$month" -le "10" ] ; then
pmonth=0`echo $month`

And for 11th and 12th month , below codes are used
Code:
else
pmonth=`echo $month`

# 10  
Old 04-03-2014
You can force a leading zero (when necessary) with the following:-
Code:
typeset -Z2 pmonth

You also have more coding than you need. Instead of:-
Code:
pmonth=`echo $month`

.... you just need:-
Code:
pmonth=$month

I hope that this neatens things for you.



Robin
# 11  
Old 04-04-2014
Or you use printf:
Code:
for i in $(seq 1 12); do printf "%02d\n" $i; done

# 12  
Old 04-11-2014
Thanks a lot ..Robin and RudiC for your suggestion .
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

2. Shell Programming and Scripting

cron to get executed on 2nd and 4th saturday of every month

Hi , i need to reboot a server during 2nd and 4th saturday every month. i have come up with the below cron 30 17 8-14 * * if ; then /rebootscript; fi # to reboot every second saturday 30 17 22-28 * * if ; then /rebootscript; fi # to reboot every fourth saturday I am wondering why it... (3 Replies)
Discussion started by: chidori
3 Replies

3. Shell Programming and Scripting

crontab: setup cronjob to run first wednesday of every month

Hi, How to setup cronjob to run first wednesday of every month. Is there a way? Thanks.. (9 Replies)
Discussion started by: Anjan1
9 Replies

4. UNIX for Dummies Questions & Answers

How to Set up a cronjob On 4th Sunday of every Month?

How to Set up a cronjob which will run On 4th Sunday of every Month at 8:00 PM :( (11 Replies)
Discussion started by: tp2115
11 Replies

5. Solaris

crontab entry to run a script on 1st of every month.

What should be the crontab entry in solaris to run a script on 1st of every month? Is this correct? 00 02 1 * * <script to be executed> (5 Replies)
Discussion started by: deepaksahni0109
5 Replies

6. UNIX for Advanced & Expert Users

Crontab For First Monday Of Every Month!!

Hi, Could any one please let me know the crontab entry for scheduling a job for every first monday of the month? Thank You in advance, Sue (2 Replies)
Discussion started by: pyaranoid
2 Replies

7. Shell Programming and Scripting

crontab entry to run every last day of the month

i've created a script which should run every last day of the month. what would be the exact crontab entry for this? thanks! (9 Replies)
Discussion started by: tads98
9 Replies

8. UNIX for Dummies Questions & Answers

crontab schedule - first thursday of every month

Instead of the first five fields, one of eight special strings may appear: string meaning ------ ------- @reboot Run once, at startup. @yearly Run once a year, "0 0 1 1 *". @annually (same as @yearly) @monthly Run once a month, "0 0 1 * *". @weekly Run once... (2 Replies)
Discussion started by: paulds
2 Replies

9. UNIX for Dummies Questions & Answers

CRONTAB: Every second Tuesday of the month

Morning everyone. You'll need to excuse me for I'm running a little empty this morning. Need to execute a job every second Tuesday of the month. Am I correct in my understanding that this isn't possible directly from crontab & hence I'll need to script. Does anyone have any similar solutions ?... (2 Replies)
Discussion started by: Cameron
2 Replies

10. UNIX for Dummies Questions & Answers

Crontab First Monday of Month only

Is there a way to setup a cronjob that will only run on the first monday of the month? (3 Replies)
Discussion started by: molonede
3 Replies
Login or Register to Ask a Question