The UNIX Forums  



Go Back   The UNIX Forums > Top Forums > Shell Programming and Scripting
Home Forums Register Rules & FAQDonate Members List Search Today's Posts Mark Forums Read

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

Reply
 
Submit Tools Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl 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 1 Week Ago
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 3,030
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl 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
Forum Sponsor
  #3 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl 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 : 1 Week Ago at 10:20 AM.
Reply With Quote
  #4 (permalink)  
Old 1 Week Ago
Registered User
 
Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Talking

edited for review

Last edited by tsmurray : 1 Week Ago at 12:45 PM.
Reply With Quote
  #5 (permalink)  
Old 6 Days Ago
Moderator
 
Join Date: Dec 2003
Location: /kernal
Posts: 597
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl 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 2 Days Ago
Registered User
 
Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl 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
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

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


web tracker

All times are GMT -5. The time now is 12:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
UNIX Forum Content Copyright ©1993-2008 SilkRoad Asia All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93