the easiest way i can think of is creating a crontab entry
59 23 * * * date > /tmp/date_yesterday
and use content of that file as input. If you need other formats -
create other files with formats you need.
hth
Michael
I know it's cheating, and others may have a better solution, but I've
handled this issue by saving the current date to a file. I have a
script that runs daily and it renames the existing file to
'yesterday', then saves the current date to 'today'. Then your script
can just 'cat yesterday' to get the prior days date.
>what could be the simplest way of obtaining yesterday's date in a
>shell script ?.. i can use bsh, csh, ksh and awk on aix4.3.
Not sure who the person was who created/posted it, but some months ago
the following script was posted. He/she probably doesn't mind me
posting it again :)
Mark
#!/bin/ksh
DATE="/bin/date" # date
typeset -L2 YMONTH # Yesterday month
typeset -R2 YDAY # Yesterday day
typeset -R4 YYEAR # Yesterday year
typeset -Z8 YDATE
YMONTH=$($DATE +%m)
YDAY=$($DATE +%d)
YYEAR=$($DATE +%Y)
if [[ $YDAY = 01 ]] && [[ $YMONTH = 01 ]]
then
((YDAY=31))
((YMONTH=12))
((YYEAR=YYEAR - 1))
elif [[ $YDAY = 01 ]] && [[ $YMONTH = @(02|04|06|08|11) ]]
then
((YDAY=31))
((YMONTH=YMONTH - 1))
elif [[ $YDAY = 01 ]] && [[ $YMONTH = @(05|07|10|12) ]]
then
((YDAY=30))
((YMONTH=YMONTH - 1))
elif [[ $YDAY = 01 ]] && [[ $YMONTH = 03 ]]
then
if ($YYEAR % 400 == 0)
then
((YDAY=29))
((YMONTH=YMONTH - 1))
else
((YDAY=28))
((YMONTH=YMONTH - 1))
fi
else
((YDAY=YDAY-1))
fi
YDATE=$YMONTH$YDAY$YYEAR
print "$YDATE"
TZ=NFT-1DFT,M3.5.0,M10.4.0
If I temporarily change this to
TZ=NFT+23DFT,M3.5.0,M10.4.0
^^^
I get yesterdays date from the date command.
In this way you let the date command handle leap years and such.
You can use the "date +FieldDescriptor" syntax to get specific parts of the date.
Regards,
Ron.
ric...@yahoo.com (richyts) wrote in message news:<d1c185ef.0201...@posting.google.com>...
>what could be the simplest way of obtaining yesterday's date in a
>shell script ?.. i can use bsh, csh, ksh and awk on aix4.3.
Play with the TZ variable. The following ksh script can be used as a
starting point:
--- cut here for tz.sh ---
#!/bin/ksh
# Usage tz.sh N [fmt_string]
# Where N is how many days to go backward
# fmt_string is optional format arg to date command
days=$1;shift
date "+%H %Z" | read t1 tn
t0=$(TZ=0 date +%H)
(( delta = t0 - t1 ))
(( adjust = delta + 24 * days ))
TZ="$tn$adjust" date "$@"
--- end of tz.sh ---
tz.sh 1 # gives you the date and time 24 hours ago
tz.sh 1 '+%d' # gives you just yesterday's day of the month
tz.sh 1 '+%Y%m%d' # gives you yesterday as yyyymmdd
tz.sh -1 # gives you tomorrow
--
Dale Talcott, Purdue University Computing Center
a...@quest.cc.purdue.edu http://quest.cc.purdue.edu/~aeh/
this one works cleanly... thanks a lot