1748165 Members
3891 Online
108758 Solutions
New Discussion юеВ

date/time script

 
SOLVED
Go to solution
Ian_77
Occasional Contributor

date/time script

Can someone please tell me how to code the following in a shell script. this needs to execute from inside another script(i.e not via cron)

If monday - Thursday execute script 1

else if friday execute script 2.
4 REPLIES 4
Fred Ruffet
Honored Contributor
Solution

Re: date/time script

WeekDay=`date %+w`
if [ $WeekDay -ge 1 -a $WeekDay -le 4 ]
then
script1
else
if [ $WeekDay -eq 5 ]
then
script2
fi
fi

...could be simplier with case, but this came first to me :)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Marcel Boogert_1
Trusted Contributor

Re: date/time script

Hi there,

With the "date +%u" you get the day of the week. Monday is 1, Tuesday is 2 ..... Sunday is 7.

MB.
Muthukumar_5
Honored Contributor

Re: date/time script

We can do this as,

# Get day information
Day=$(date +'%a')

if [[ "$Day" = "Mon" || "$Day" = "Thu" ]]
then

# Execute script 1

elif [[ "$Day" = "Fri" ]]
then

# Execute script 2

fi

Regards
Muthu
Easy to suggest when don't know about the problem!
Rodney Hills
Honored Contributor

Re: date/time script

Their is a nifty tool by Clay called "caljd" for doing date calculations.

Check this thread...

http://forums1.itrc.hp.com/service/forums/parseCurl.do?CURL=%2Fcm%2FQuestionAnswer%2F1%2C%2C0x1fb33a7b3682d611abdb0090277a778c%2C00.html&admit=716493758+1095084205608+28353475

HTH

-- Rod Hills
There be dragons...