Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variables

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
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?

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"
}
 
PHV,

Thanks. No luck here.

/tmp>sh test5.sh
Yesterday: Mon Jul 12 17:41:24 EDT 2004
Tomorrow: Tue Jul 13 17:41:24 EDT 2004
Next week: 2004-07-12

 
Can you please post the value of your TZ environment variable ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
And what is displayed when you type this ?
TZ=EST29EDT date

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi,

It displays the following

Mon Jul 12 18:07:27 EDT 2004
 
So, seems that HP-UX allows only +/-24 hours displacement.
Sorry.
 
PHV,

Only +24. Yesterday: Mon Jul 12 17:41:24 EDT 2004
is not right.
 
And does above code make any sense to you? If not please suggest something. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top