LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 02-25-2009, 08:56 AM   #1
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Rep: Reputation: 15
Cronjob for every second Saturday of the month


I was thinking of implementing a script in crontab to run a job every second Saturday of every month, or alternatively every two weeks on a Saturday.

I'm a bit stumped with this one, not sure how it would be specified?

I was thinking along the lines of:

Code:
10  7  *  *  6  command to be executed
The above would run every Saturday at 07:10 though.


Anyone have any ideas on this?
 
Old 02-26-2009, 04:30 AM   #2
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Original Poster
Rep: Reputation: 15
OK, think I figured it out.

I'd specify the crontab to run whichever script I want to run every Saturday. The script itself though would then just do the following:

Code:
PTS=/path/to/real/script

# -------------------------------------------------------------------------------------------------------------------------------

WDIR=`cat $PTS/counter.log`

# Is it the second Saturday?

if [ $WDIR == "1" ] ;
then
  cat /dev/null > $PTS/counter.log
  exit
elif [ $WID -ne "1" ] ;
then
  echo "1" > $PTS/counter.log
  $PTS/jobthatshouldberuneverysecondsaturday.sh
  exit
fi

Haven't tested it yet, but it should work right?
 
Old 02-26-2009, 04:49 AM   #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
You can just add a control statement at the beginning of the script using the date command to check if the current day is Saturday and if it is the second of the month (it will be between the 8th and 14th of the month):
Code:
#!/bin/bash
if [ $(date +%w) -eq 6 -a $(date +%e) -gt 7 -a $(date +%e) -le 14 ]
then
  <code to be executed here>
else
  <do something>
  exit
fi
 
Old 02-26-2009, 04:56 AM   #4
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
You can just add a control statement at the beginning of the script using the date command to check if the current day is Saturday and if it is the second of the month (it will be between the 8th and 14th of the month):
Code:
#!/bin/bash
if [ $(date +%w) -eq 6 -a $(date +%e) -gt 7 -a $(date +%e) -le 14 ]
then
  <code to be executed here>
else
  <do something>
  exit
fi
Mmm, never thought about it like that...

Thanks Colucix, I'll give it a go and see how it goes.
 
  


Reply

Tags
cron, second



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
Cronjob - Monthly on Saturday joerilinux Linux - Newbie 4 09-18-2009 03:08 AM
transform month number to month name in php ALInux Programming 1 11-09-2005 10:45 AM
cron: every 3 weeks on a saturday rgiggs Slackware 19 09-26-2005 04:59 PM
On the lighter side of Saturday morning... JordanH General 5 05-01-2005 12:11 AM
Starting day of month, month length chrisk5527 Programming 2 03-03-2004 04:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 05:55 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