The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
syntex error script any suggestions kim187 Shell Programming and Scripting 5 04-29-2008 10:56 PM
Performance problem with my script ...suggestions pls vivsiv Shell Programming and Scripting 2 02-22-2008 11:25 PM
Suggestions Req ravi.sadani19 SUN Solaris 1 06-01-2007 03:29 AM
Looking for Suggestions... scottsl UNIX for Advanced & Expert Users 1 12-17-2005 08:32 AM
How can i proceed on this (datecheck) gopskrish UNIX for Dummies Questions & Answers 2 06-27-2005 01:16 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-09-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
Stumble this Post!
Need suggestions about a datecheck script

I'm currently running a script that checks to see if a laptop is on the network, and if it is it backs up, if not it retries it later.

Anyway, our backup scheduling has changed. I need to check if today's date is the Thursday after the first Wednesday of every month. This is made slightly more difficult by the fact that the first Thursday doesn't always follow the first Wednesday (in cases where the 1st day of the month happens to be Thursday).

Is there an easy way to do this?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-09-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,846
Stumble this Post!
What you said == first occurrence of Thursday in a month, regardless of Wednesday.
Code:
#!/bin/ksh
is_first_thursday()
{
    retval=0
    typeset -i day=$(date +%d)
    if [[ $day -lt 8 ]];  then 
           if [[ "`date +%A`" = "Thursday" ]] ; then
                 retval=1
           fi
    fi 
    echo $retval
}
usage:
Code:
ok=$(is_first_thursday)
if [[ $ok - eq 1 ]] ; then
    # do stuff because it is first thursday
fi
Reply With Quote
  #3 (permalink)  
Old 05-09-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
Stumble this Post!
Thanks for the quick reply Jim!!

What I was looking for is the First Thursday after the First Wednesday of every month. There must be a previous Wednesday in the month.


I'm trying to explain it this way because, for example, May 2008:

1st Thursday = Day 1
1st Wednesday = Day 7
1st Thursday after the first Wednesday = Day 8.

So a simple "First Thursday" is not the same thing as the "First Thursday after the First Wednesday".

I appreciate your all your help mate!

Last edited by tsmurray; 05-09-2008 at 08:20 AM.
Reply With Quote
  #4 (permalink)  
Old 05-09-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
Stumble this Post!
Talking

edited for review

Last edited by tsmurray; 05-09-2008 at 10:45 AM.
Reply With Quote
  #5 (permalink)  
Old 05-10-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 954
Stumble this Post!
Using ksh93 ..
Code:
$ printf "%(%D)T\n" "first wednesday may 2008"
05/07/08
$ printf "%(%D)T\n" "$(printf "%(%D)T\n" "first wednesday may 2008") + 1 day"
05/08/08
$
Reply With Quote
  #6 (permalink)  
Old 05-14-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
Stumble this Post!
Unhappy didn't work

Thanks for the reply fpmurphy, but it doesn't seem to work in my version of ksh.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0