From: Will Mernagh (will.mernagh at domain comnitel.com)
Date: Mon 13 Aug 2001 - 18:08:14 IST
Okay no more awk but this script is going to run a solaris also and solaris
does not have -d yesterday opting.
I found a way around it though which the following function (For ksh)
day_shift () {
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 "$ at domain "
}
Thanks anyway
-----Original Message-----
From: kevin lyda [mailto:kevin at domain suberic.net]
Sent: 13 August 2001 17:46
To: Will Mernagh
Cc: ILUG
Subject: Re: [ILUG] data conversion in bash
On Mon, Aug 13, 2001 at 04:14:59PM +0100, Will Mernagh wrote:
> DAYa=`date | awk '{print $3}'`
> DAYb=`expr $DAYa - 1`
> MONTH=`date '+%m'`
> YEAR=`date | awk '{print $6}'`
> DATEa=$DAYa'-'$MONTH'-'$YEAR
> DATEb=$DAYb'-'$MONTH'-'$YEAR
>
> How can I change the month from 08 to 8. I was thinking of using
${MONTH/0/}
please. stop. using. awk. it's not often that i say this, but you
don't need awk here. go read the date man page and delete every line
except the DATEa= and DATEb= ones. and for them, replace them with
something like:
DATEa=`date "%x-%x-%x"`
DATEb=`date -d yesterday "%x-%x-%x"`
the various %x's are to be discovered by reading the man page. note the
-d yesterday - your code would fail on the first of the month.
finally if there's *any* chance your code will run at midnight, then do
something like this:
NOW=`date "%z/%z/%z"` # NOW should equal mm/dd/yyyy
DATEa=`date -d "$NOW" "%x-%x-%x"`
DATEb=`date -d "$NOW - 1 day ago" "%x-%x-%x"`
%z/%z/%z above should be replaced by some incantation that yields the
american date format: mm/dd/yyyy
kevin
-- kevin at domain suberic.net simple four line sigs - fork()'ed on 37058400 bandwidth friendly; nice to do. meatspace place: home some admins clueless. http://suberic.net/~kevin --netiquette haiku 2001
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:11:36 GMT