i have 3 parameters of date "Sep 30 Mon" (Month,DayNumber,Day), and i want to make a shell script that shows the quantity of days left to reach to Sep 30 Mon.
How can i do it?
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
I am assuming you want to calculate the number of days until the closest day which will happen to be September 30 on Monday, be it any year. this script works for me (you can change the "Monday" in the condition to another day of week, same with other days/months. The script defines which year it is right now and counts from there. It uses the one-liner from the link to the stack-overflow thread under your question
YEAR=$(date +%Y) DAY=$(date -d "30 SEP $YEAR" +%A) until [[ $DAY == "Monday" ]] do YEAR=$(($YEAR+1)) DAY=$(date -d "30 SEP $YEAR" +%A) done echo $(expr '(' $(date -d $YEAR/9/30 +%s) - $(date +%s) + 86399 ')' / 86400) " days until deadline"