Comment Korn Shell Script to find last day of month (Score 1) 185
Here is a script I put together to find the last day of the month using 'cal' -useful for checks in a cron job for only the last day of the month.
#!/bin/ksh
integer count=0
cal | while read A B C D E F G
do
((count+=1))
if ((count>3)) ; then
if [[ -z $A ]] ; then
break
elif [[ -z $B ]] ; then
lastday=$A
break
elif [[ -z $C ]] ; then
lastday=$B
break
elif [[ -z $D ]] ; then
lastday=$C
break
elif [[ -z $E ]] ; then
lastday=$D
break
elif [[ -z $F ]] ; then
lastday=$E
break
elif [[ -z $G ]] ; then
lastday=$F
break
else
lastday=$G
fi
fi
done
print "$lastday"
exit 0
#!/bin/ksh
integer count=0
cal | while read A B C D E F G
do
((count+=1))
if ((count>3)) ; then
if [[ -z $A ]] ; then
break
elif [[ -z $B ]] ; then
lastday=$A
break
elif [[ -z $C ]] ; then
lastday=$B
break
elif [[ -z $D ]] ; then
lastday=$C
break
elif [[ -z $E ]] ; then
lastday=$D
break
elif [[ -z $F ]] ; then
lastday=$E
break
elif [[ -z $G ]] ; then
lastday=$F
break
else
lastday=$G
fi
fi
done
print "$lastday"
exit 0