1833159 Members
3295 Online
110051 Solutions
New Discussion

allocate directory

 
Ralf Buchhold
Regular Advisor

allocate directory

Hello
I have to allocate a directory with:
today -1. Example:
Today: 29.11.2004
Directoryname: 20041128
Attention! the first of a month !
Thanks Ralf
3 REPLIES 3
Thierry Poels_1
Honored Contributor

Re: allocate directory

hi,

do a search here on "caljd" and you'll get Clay's script to manipulate dates.

otherwise try this:
$ date
Mon Nov 29 16:13:09 MET 2004
$ yymmdd=`(TZ=MET+24METDST ; date +%Y%m%d)`
$ echo $yymmdd
20041128
$ date
Mon Nov 29 16:13:15 MET 2004

regards,
Thierry Poels.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
A. Clay Stephenson
Acclaimed Contributor

Re: allocate directory

Playing with the TZ variable only works over a limited range of TIMEZONES. Perl's localtime() plus the time() - 86400 function will allso work nicely. This is now I would do it:

YESTERDAY=$(caljd.sh -y -s $(caljd.sh -p 1))
echo "Yesterday = ${YESTERDAY}"

I'll attach the caljd script. Invoke it as caljd.sh -u for full usage and many examples.

If it ain't broke, I can fix that.
Hein van den Heuvel
Honored Contributor

Re: allocate directory


Because I often work in larger perl scripts I like the perl solutions. I would probably have perl do the mkdir and so on.

One (of many) ways to solve this in perl is:

perl -e '@t=localtime(time()-86400);printf ("%d%02d%02d\n",1900+@t[5],1+@t[4],@t[3])'

fwiw,
Hein.