How to check if today is a weekend using bash or even perl?
I want to prevent certain programs to run on a weekend.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use something like:
date +%ugives you the day of the week from Monday (1) through to Sunday (7). If it’s greater than 5 (Saturday is 6 and Sunday is 7), then it’s the weekend.So you could put something like this at the top of your script:
Or the more succinct:
To check if it’s a weekday, use the opposite sense (
< 6rather than> 5):