top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Run script on cron job only run on first Saturday every month [CLOSED]

0 votes
1,438 views

One of our script need run on first Saturday every month. We have following setup on cron job but it run every Saturday.

15 04 1-7 * 6 /xxx/monthlybk.sh

Any one know how to fix it?

closed with the note: None
posted Jul 30, 2013 by Amit Parthsarthi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

4 Answers

0 votes

I don't believe cron has any concept of the first day-of-week of each month, so you'll need to put some code into your script to exit if its NOT the first day-of-week of each month.

answer Jul 30, 2013 by Jagan Mishra
0 votes

It certainly doesn't. However, I'm surprised crontab entry *doesn't* work: it should run only on Sat, and only on when it's somewhere between the 1st and the 7th, which could only be the first Sat.

answer Jul 30, 2013 by Deepankar Dubey
The conditions are ORd, so the job should run every Saturday and every day from the first to the seventh (which will include a Saturday).
0 votes

maybe...

 15 04 * * 6 test $(date +"%d") -le 07 && /xxx/monthlybk.sh
answer Jul 30, 2013 by Sheetal Chauhan
0 votes

Run an incremental backup every day of the month except sundays

03 03 1-31 * * test date +%a != Sun && /usr/local/bin/backup-rsch-inc

Run a full backup on the first sunday of the month

07 03 1-7 * * test date +%a = Sun && /usr/local/bin/backup-rsch-full

answer Jul 31, 2013 by Sonu Jindal
Similar Questions
–1 vote

from man crontab:

Step values can be used in conjunction with ranges. Following a range with / specifies skips of the number's value through the range. For example 0-23/2 can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is 0,2,4,6,8,10,12,14,16,18,20,22). Steps are also permitted after an asterisk, so if you want to say every two hours, just use */2

As an example, I see:

~# 
~# cat /etc/cron.d/leafnode 
# Cron entries for Leafnode.
# Run /etc/news/leafnode/do-fetch-news every hour.
8 * * * * news if [ -x /etc/news/leafnode/do-fetch-news ]; then /etc/news/leafnode/do-fetch-news; fi

now, every, let's say, two hours I want to run "killall fetchnews" because it has a tendency to stall. Would that look like:

#cron to kill defunct fetchnews
* */2 * * * killall fetchnews

(leaving out the logic of looking for a zombie process (if that's correct terminology))

0 votes

How do I execute certain shell script at a specific intervals in Linux using cron job?
Please provide examples using different time periods.

...