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?
What you said == first occurrence of Thursday in a month, regardless of Wednesday.
#!/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:
ok=$(is_first_thursday)
if [[ $ok - eq 1 ]] ; then
# do stuff because it is first thursday
fi
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!
Using ksh93 ..
$ 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
$
Thanks for the reply fpmurphy, but it doesn't seem to work in my version of ksh.