Hi,
Can someone help with this code please? I want to know if there are too many variables in as declared in this code block. I am using some variables after if block. Is it a good design? I am reading database parameters from dbprofile. Is that ok? Mine being an HPUX system, I am forced to use the date function as shown below? (I tried yesterday's date faq. It doesn't work in my case) Any suggestions to improve that code?
Can someone help with this code please? I want to know if there are too many variables in as declared in this code block. I am using some variables after if block. Is it a good design? I am reading database parameters from dbprofile. Is that ok? Mine being an HPUX system, I am forced to use the date function as shown below? (I tried yesterday's date faq. It doesn't work in my case) Any suggestions to improve that code?
Code:
function_name ()
{
local SQLTEMP="/tmp/ting.out"
local DATETMP="/tmp/datetmp.out"
local ARCDIR="/u06/arc"
if [ `date | awk '{print $1}'` = "Mon" ]
then
local DAY=`date | awk '{print $3}'`
local MONTH=`date | awk '{print $2}'`
local YEAR=`date | awk '{print $6}'`
local sunday_date=`calculate_date $DAY $MONTH $YEAR date`
echo "`calculate_date $sunday_date date date`" > $DATETMP
local SATDAY=`cat $DATETMP | cut -c1-2`
local SATMONTH=`cat $DATETMP | cut -c4-6`
local SATYEAR=`cat $DATETMP | cut -c8-11`
local DBPROFILE=/home/dbprofile.dat
local HostName=`awk '/DTSRV/{ print $1 }' $DBPROFILE`
local User=`awk '/DTSRV/{ print $4 }' $DBPROFILE`
local UserPass=`awk '/DTSRV/{ print $5 }' $DBPROFILE`
local DATETIME=`date | awk '{printf("%0s %0s %0s", $2, $3, $4)}'`
count=0
Code:
calculate_date ()
{
local DAY=$1
local MONTH=$2
local YEAR=$3
local FORMAT=$4
# if it is the first day of the month
if [ $DAY -eq 01 ]
then
# if it is the first month of the year
if [ $MONTH -eq 01 ]
then
# make the month as 12
MONTH=12
# deduct the year by one
YEAR=`expr $YEAR - 1`
else
# deduct the month by one
MONTH=`expr $MONTH - 1`
if [ "$MONTH" -le 9 ]
then
MONTH=0$MONTH
fi
fi
DAY=`cal $MONTH $YEAR | awk 'NF != 0{ last = $0 }; END{ print last }' | awk '{ print $NF }'`
else
# deduct the day by one
DAY=`expr $DAY - 1`
if [ "$DAY" -le 9 ]
then
DAY=0$DAY
fi
fi
if [ "$FORMAT" = "stamp" ]
then
print ${YEAR} ${MONTH} ${DAY}
else
print ${DAY} ${MONTH} ${YEAR}
fi
}
get_stamp ()
{
local DAY=`date +%e`
local MONTH=`date +%m`
local YEAR=`date +%Y`
yesterday=`calculate_date $DAY $MONTH $YEAR date`
stamp=`calculate_date $yesterday stamp`
stamp=$(echo "$stamp" | sed 's! !!g')
print "${stamp}0700"
}