LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 02-25-2009, 09: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: 142
Thanked: 0
Cronjob for every second Saturday of the month


[Log in to get rid of this advertisement]
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?
kinetik is offline  
Tag This Post , ,
Reply With Quote
Old 02-26-2009, 05: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: 142
Thanked: 0

Original Poster
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?
kinetik is offline     Reply With Quote
Old 02-26-2009, 05:49 AM   #3
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,134
Thanked: 465
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
colucix is offline     Reply With Quote
Old 02-26-2009, 05: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: 142
Thanked: 0

Original Poster
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.
kinetik is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


All times are GMT -5. The time now is 07:45 PM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration