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?

closed as off-topic by Jenny D, Thomas, Ward Feb 12 at 1:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Ward
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Something like this? stackoverflow.com/questions/6282059/… – pmarkoulidakis Feb 7 at 20:07
  • Hello, yes, something like that, but how can i replace 2011/11/1 to Sep 30 Mon ? echo $(expr '(' $(date -d 2011/11/1 +%s) - $(date +%s) + 86399 ')' / 86400) " days until deadline" – codeman Feb 7 at 20:29

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" ]]
DAY=$(date -d "30 SEP $YEAR" +%A)

echo $(expr '(' $(date -d $YEAR/9/30 +%s) - $(date +%s) + 86399 ')' / 86400) " days until deadline"

Not the answer you're looking for? Browse other questions tagged or ask your own question.