hello script gurus. I am in need of your guidance with this script. I am having problems when script runs in January and September. Any help would be greatly appreciated!
*********************************
#!/usr/bin/ksh93
#DATE:11/29/04
#NAME: /usr/scripts/setarperdays.ksh
#
# Script determines next, current, last month's and two month's ago last day of
# month. It then subtracts one day.
# Puts day variables into sascarperdays.p file
# LOGIC: Take the current month's number of days and subtract one
# to equal arperdays[1] = day number variable
#
# arperdays[1] = (days in next month) - 1
# arperdays[2] = (days in current month) -1
# arperdays[3] = (days in last month) -1
# arperdays[4] = (days in two months ago) -1
################################################################################
cd /usr/scripts
#
N=1
# Last day of next month
typeset -Z4 year=$(date +%Y)
typeset -Z2 month=$(( $(date +%m) + 1 ))
if [ $month -eq 13 ] ;
then
(( year += 1 ))
month=1
fi
next_month=${year}${month}
A=`echo $next_month|cut -c 1-4` # 4 digit year
B=`echo $next_month|cut -c 5-6` # 2 digit month
C=`cal "$B" "$A"`
D=${C##*[!0-9]}
V1=`expr $D - $N`
# thread822-839081 from tek-tips.com
# Last Day of This Month
val=$(cal)
val=${val##*[!0-9]}
V2=`expr $val - $N`
# thread80-768784 from tek-tips.com
# Last day of last month
typeset -Z4 year=$(date +%Y)
typeset -Z2 month=$(( $(date +%m) -1 ))
if [ $month -eq 0 ] ;
then
(( year -= 1 ))
month=12
fi
last_month=${year}${month}
E=`echo $last_month|cut -c 1-4` # 4 digit year
F=`echo $last_month|cut -c 5-6` # 2 digit month
G=`cal "$F" "$E"`
H=${G##*[!0-9] }
V3=`expr $H - $N`
# Last day of two months ago
typeset -Z4 year=$(date +%Y)
typeset -Z2 month=$(( $(date +%m) -2 ))
if [ $month -le 0 ] ;
then
(( year -= 1 ))
month=12
fi
two_month_ago=${year}${month}
I=`echo $two_month_ago|cut -c 1-4` # 4 digit year
J=`echo $two_month_ago|cut -c 5-6` # 2 digit month
K=`cal "$J" "$I"`
H=${K##*[!0-9]}
V4=`expr $H - $N`
echo "for each sasc where sasc.cono = 1 exclusive-lock: \n
assign \n
arperdays[1] = $V1 /* days in next month -1 */ \n
arperdays[2] = $V2 /* days in current month -1 */ \n
arperdays[3] = $V3 /* days in last month -1 */ \n
arperdays[4] = $V4 . /* days in last 2 months ago -1 */ \n " > sascarperdays.p
*********************************
#!/usr/bin/ksh93
#DATE:11/29/04
#NAME: /usr/scripts/setarperdays.ksh
#
# Script determines next, current, last month's and two month's ago last day of
# month. It then subtracts one day.
# Puts day variables into sascarperdays.p file
# LOGIC: Take the current month's number of days and subtract one
# to equal arperdays[1] = day number variable
#
# arperdays[1] = (days in next month) - 1
# arperdays[2] = (days in current month) -1
# arperdays[3] = (days in last month) -1
# arperdays[4] = (days in two months ago) -1
################################################################################
cd /usr/scripts
#
N=1
# Last day of next month
typeset -Z4 year=$(date +%Y)
typeset -Z2 month=$(( $(date +%m) + 1 ))
if [ $month -eq 13 ] ;
then
(( year += 1 ))
month=1
fi
next_month=${year}${month}
A=`echo $next_month|cut -c 1-4` # 4 digit year
B=`echo $next_month|cut -c 5-6` # 2 digit month
C=`cal "$B" "$A"`
D=${C##*[!0-9]}
V1=`expr $D - $N`
# thread822-839081 from tek-tips.com
# Last Day of This Month
val=$(cal)
val=${val##*[!0-9]}
V2=`expr $val - $N`
# thread80-768784 from tek-tips.com
# Last day of last month
typeset -Z4 year=$(date +%Y)
typeset -Z2 month=$(( $(date +%m) -1 ))
if [ $month -eq 0 ] ;
then
(( year -= 1 ))
month=12
fi
last_month=${year}${month}
E=`echo $last_month|cut -c 1-4` # 4 digit year
F=`echo $last_month|cut -c 5-6` # 2 digit month
G=`cal "$F" "$E"`
H=${G##*[!0-9] }
V3=`expr $H - $N`
# Last day of two months ago
typeset -Z4 year=$(date +%Y)
typeset -Z2 month=$(( $(date +%m) -2 ))
if [ $month -le 0 ] ;
then
(( year -= 1 ))
month=12
fi
two_month_ago=${year}${month}
I=`echo $two_month_ago|cut -c 1-4` # 4 digit year
J=`echo $two_month_ago|cut -c 5-6` # 2 digit month
K=`cal "$J" "$I"`
H=${K##*[!0-9]}
V4=`expr $H - $N`
echo "for each sasc where sasc.cono = 1 exclusive-lock: \n
assign \n
arperdays[1] = $V1 /* days in next month -1 */ \n
arperdays[2] = $V2 /* days in current month -1 */ \n
arperdays[3] = $V3 /* days in last month -1 */ \n
arperdays[4] = $V4 . /* days in last 2 months ago -1 */ \n " > sascarperdays.p