Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BASH Script question, Day of Week condition

Status
Not open for further replies.

Narizz28

MIS
Mar 8, 2001
161
Forgive my ignorance in advance, I'm an experienced Windows administrator and have very limited knowledge of shell scripting for Unix.

I am trying to modify a cron job that calls an FTP.sh script into calling the original script if it's Saturday, and a different one otherwise (FTP2.sh). Using the BASH shell, would the syntax be something like this:

Code:
if [ `date +%A`="Saturday" ] then
FTP.sh
else
FTP2.sh
fi

I'm EXTREMELY green on bash scripting syntax. Does the above look anything near correct?

Thanks in advance.
 
Hi:

Stefan is right about crontab, but if, for some reason, you choose not to, the placement of your then statement is a problem; either place before the 'then' or place 'then' on a separate line. Also, you need a space between the equal sign and the back tic:


if [ $(date +%A) = "Sunday" ]
then
echo "it's sunday"
else
echo "it's NOT"
fi

Although it's not required I'm using $(..) instead of `..`

Regards,

Ed
 
Thank you very much olded, that's exactly why I asked.

Thanks again for helping this old Winders dood! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top