I wrote this small script to have a tool that can show how many days are left
till defined date, it is running cyclically every 60 seconds until manually stopped,
or until condition of cycle is met.
#!/bin/bash
# Script shows number of integer days from now till defined date
clear ; read -p " Date of event (year-month-day): " n
D1=`date +%s` ; D2=`date -d $n +%s` ;
DIFFSEC=$((D2-D1)) ; DIFFMIN=$((DIFFSEC/60))
DIFFHRS=$((DIFFMIN/60)) ; DIFFDAY=$((DIFFHRS/24))
MSG="Event will happen after:"
while [ $DIFFSEC -gt 0 ] ; do
if [ $DIFFDAY -ge 60 ] ; then
# Color of output is unchanged if more than 60 days till event
echo -en " $MSG $DIFFDAY days \r"
D1=`date +%s` ; D2=`date -d $n +%s` ;
DIFFSEC=$((D2-D1)) ; DIFFMIN=$((DIFFSEC/60))
DIFFHRS=$((DIFFMIN/60)) ; DIFFDAY=$((DIFFHRS/24))
elif [ $DIFFDAY -ge 30 ] && [ $DIFFDAY -lt 60 ] ; then
# Color of output is yellow if event between 30 and 60 days
echo -en " $MSG \033[1;33m $DIFFDAY days \r"
D1=`date +%s` ; D2=`date -d $n +%s` ;
DIFFSEC=$((D2-D1)) ; DIFFMIN=$((DIFFSEC/60))
DIFFHRS=$((DIFFMIN/60)) ; DIFFDAY=$((DIFFHRS/24))
else
# Color of output is green if less than 30 days till event
echo -en " $MSG \033[1;32m $DIFFDAY days \r"
D1=`date +%s` ; D2=`date -d $n +%s` ;
DIFFSEC=$((D2-D1)) ; DIFFMIN=$((DIFFSEC/60))
DIFFHRS=$((DIFFMIN/60)) ; DIFFDAY=$((DIFFHRS/24))
fi
sleep 60 ; done