LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-29-2012, 10:01 AM   #1
jayakumar01
Member
 
Registered: Nov 2011
Posts: 106

Rep: Reputation: Disabled
How to run a script on first sunday of every month


Hi All.

I had planned to run crontab schedule to backup database backup of every dunday of every month .Can anyone help me how can i set the crontab schedule to run on first sunday of every month
 
Old 05-29-2012, 10:39 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,789

Rep: Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217
You can't do that entirely within a crontab entry. Best alternative is to have cron run the script every Sunday, and then have the script itself check whether the day of month is greater than 7:
Code:
test $(date +%-d) -gt 7 && exit 0  # If not the first week, do nothing (successfully)
 
Old 05-29-2012, 02:40 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
In alternative you can do the check in the crontab entry itself, e.g.
Code:
0 18 * * 0 [ $(date +\%e) -le 7 ] && /path/to/my/script.sh
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Scheduling a CRON job to run on the first Sunday of the month New2Linux2 Linux - Software 10 11-08-2016 12:25 PM
dcron - run script last friday of month cotton213 Linux - Software 7 06-25-2012 04:03 PM
How calculate first and second sunday of month. beckss Programming 4 03-23-2012 03:45 AM
how to get the last sunday of March and October in shell script dpk Linux - Software 11 03-18-2011 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration