The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-30-2008 01:56 AM
Performance problem with my script ...suggestions pls vivsiv Shell Programming and Scripting 2 02-23-2008 03:25 AM
Suggestions Req ravi.sadani19 SUN Solaris 1 06-01-2007 06:29 AM
Looking for Suggestions... scottsl UNIX for Advanced & Expert Users 1 12-17-2005 12:32 PM
How can i proceed on this (datecheck) gopskrish UNIX for Dummies Questions & Answers 2 06-27-2005 04:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-09-2008
tsmurray tsmurray is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
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?
  #2 (permalink)  
Old 05-09-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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
  #3 (permalink)  
Old 05-09-2008
tsmurray tsmurray is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
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 11:20 AM..
  #4 (permalink)  
Old 05-09-2008
tsmurray tsmurray is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Talking

edited for review

Last edited by tsmurray; 05-09-2008 at 01:45 PM..
  #5 (permalink)  
Old 05-10-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
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
$
  #6 (permalink)  
Old 05-14-2008
tsmurray tsmurray is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 4
Unhappy didn't work

Thanks for the reply fpmurphy, but it doesn't seem to work in my version of ksh.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0