- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: File Name based on Prior date
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 04:03 AM
02-03-2004 04:03 AM
I need to create a filename based upon the previous day's date but here is where it gets hard. If today is Monday, I want to use the previous Friday. If today is Tuesday through Friday, I want to use the previous day.
I would like the filename to look like Dyymmdd.BKUP.
The date command doesn't seem to do what I want. Any ideas?
Thanks,
Jim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 04:16 AM
02-03-2004 04:16 AM
SolutionFNAME="D$(caljd.sh -C -y -s $(caljd.sh -p 1 -x 0 -x 6)).BKUP"
Search the Forums for caljd.sh but make sure that you find Version 2.22 (or later). There is also a Perl version, caljd.pl that works exactly the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 04:19 AM
02-03-2004 04:19 AM
Re: File Name based on Prior date
A little bit of perl (only to get the time since epoch - you should have in your /usr/contrib/bin) and adb should get you through it. You will get full date as YDATE and you can chop to whatever you want like MYDATE and use it as an extension.
-Sri
#!/usr/bin/ksh
NOW=$(/usr/contrib/bin/perl -e "printf("%d\n",time())")
WEEK=$(date +%a)
if [ "$WEEK" != "Mon" ]
then
COUNT=1
else
COUNT=3
fi
(( TIME = $NOW - ( $COUNT * 86400 ) ))
YDATE=$(echo "0d${TIME}=Y" |adb)
echo Full Date is $YDATE
MYDATE=$(echo $YDATE|awk '{print $2"-"$3"-"$1}')
echo $MYDATE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 04:29 AM
02-03-2004 04:29 AM
Re: File Name based on Prior date
TODAY=`date -u +%a`
case $TODAY in
MON) YSDAY=FRI;;
TUE) YSDAY=MON;;
WED YSDAY=TUE;;
THU YSDAY=WED;;
FRI YSDAY=THU;;
esac
filename=$YSDAYmmddyy
This of course only fixes the day of the week, not the date itself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 04:29 AM
02-03-2004 04:29 AM
Re: File Name based on Prior date
The first version gives you a file name like D20040202.BKUP.
#!/usr/bin/sh
DOW=$(caljd.sh -w)
if [ "$DOW" = 1 ]
then
DATE=$(caljd.sh -y -s $(caljd.sh -p 3))
else
if [ "$DOW" != 6 -a "$DOW" != 0 ]
then
DATE=$(caljd.sh -y -s $(caljd.sh -p 1))
fi
fi
FILE="D${DATE}.BKUP"
echo $FILE
This version cuts the leading '20' off of the year to give you a file name like D040202.BKUP:
#!/usr/bin/sh
DOW=$(caljd.sh -w)
if [ "$DOW" = 1 ]
then
DATE=$(caljd.sh -y -s $(caljd.sh -p 3))
else
if [ "$DOW" != 6 -a "$DOW" != 0 ]
then
DATE=$(caljd.sh -y -s $(caljd.sh -p 1))
fi
fi
DATE=$(echo $DATE | cut -c 3-8)
FILE="D${DATE}.BKUP"
echo $FILE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 04:33 AM
02-03-2004 04:33 AM
Re: File Name based on Prior date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 03:14 PM
02-03-2004 03:14 PM
Re: File Name based on Prior date
Does that D stand for?
Just a "D" or "Day of the week"?
If it is a "D" check out:
while (1){
$t -= 86400;
($x,$x,$x,$d,$m,$y,$w,$x,$x) = localtime($t);
last if ($w % 6);
}
printf ("D%02d%02d%02d.BKUP\n",$y%100,++$m,$d;
If it means "Day of the week" try this.
(remove testing code when satisfied)
$x = shift @ARGV;
$t = time + ($x * 86400);
while (1){
$t -= 86400;
($x,$x,$x,$d,$m,$y,$w,$x,$x) = localtime($t);
last if ($w % 6);
}
printf ("%s%02d%02d%02d\n",("Mon","Tue","Wed","Thu","Fri")[--$w],$y%100,++$m,$d;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 03:17 PM
02-03-2004 03:17 PM
Re: File Name based on Prior date
caljd.sh-->clay.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2004 03:23 PM
02-03-2004 03:23 PM
Re: File Name based on Prior date
I forgot to exlicitly indicate that my examples are PERL scripts. Not that there can be much doubt, but still.
[Arrghh... I wish I could just edit that reply]
Hein.