does any one have any ideas how i would go about calculating the number of days left in the month from a bash script ?. I want to do some operations on a csv file according to the result
usage: sh getdays.sh 08 2008
if [ -n "$1" ]
then
dim_m=$1
dim_y=$2
else
eval `date "+dim_m=%m dim_y=%Y"`
fi
_DAYS_IN_MONTH=`cal $dim_m $dim_y | egrep -v '[A-Za-z]' | wc -w`
echo $_DAYS_IN_MONTH
EDIT: This only gets the number of total days in month.
@ikon thanks for that so to calculate the number of days left in the month i used (added)
which seem to work great thanks alot
Kind regards dunryc
usage scriptname month(MM) year(YYYY)
let no_of_days_left_in_month=`cal $1 $2|sed '/^$/d'|tail -1|awk '{print $NF}'`-`date "+%d"`
echo "$no_of_days_left_in_month"
I get nothing...
# sh dom.sh 08 2008
#
fnsonlq0-/home/fnsonlq0/vidya_perl>cat calculate
let no_of_days_left_in_month=`cal $1 $2|sed '/^$/d'|tail -1|awk '{print $NF}'`-`date "+%d"`
echo "\n$no_of_days_left_in_month\n"
fnsonlq0-/home/fnsonlq0/vidya_perl>calculate 08 2008
19
fnsonlq0-/home/fnsonlq0/vidya_perl>
I AM NOT GETTING ANY PROBLEM!!!!!!!
I see you changed the string:
let no_of_days_left_in_month=`cal $1 $2|sed '/^$/d'|tail -1|awk '{print $NF}'`-`date "+%d"`
echo "\n$no_of_days_left_in_month\n"
oh sorry ya variable name was missspelled
cal | awk 'BEGIN{ RS="";"date +%d" | getline day}{ print $NF-day}'