- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: compare file's date with machine 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
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
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-12-2012 01:48 AM
02-12-2012 01:48 AM
compare file's date with machine date
Hi Gurus ,
Script to compare file's date with machine date.
d=$(date | awk '{print $2,$3}')
d2=$(ls -la $file | awk '{print $6,$7}')
if [ "$d" = "$d2" ]
then
echo "they match"
elif [ "$d" != "$d2" ]
then
echo "Check date"
fi
The issue is that when the system date is single digit , like "Feb 2" , the value of
d will be "Feb 2" in my machine (extra space between Feb and 2)
and the value of d2 will be "Feb 2" , this will led to a incorrect run of script.
The above script will run fine if the date is double digit , like "Feb 12".
Machine is running Hp ux v3.
Referance :
John Meissner solution in the tread
http://h30499.www3.hp.com/t5/System-Administration/file-date-verses-current-date/m-p/2879437/highlight/true#M100534
- Tags:
- date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2012 01:55 AM
02-12-2012 01:55 AM
Re: compare file's date with machine date
>d=$(date | awk '{print $2,$3}')
There is no need to use awk here. date(1) has a "+ format" that will do this.
>elif [ "$d" != "$d2" ]
There is no need to check twice.
What locale are you using? Some scummy locales suppress blanks. Some have blanks.
The "right" local has leading zeros.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2012 02:55 AM
02-12-2012 02:55 AM
Re: compare file's date with machine date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2012 01:23 PM
02-12-2012 01:23 PM
Re: compare file's date with machine date
>I will try something like day=$(date +%d)
(Using "%e" would have that space.)
If you don't want to fiddle with locales and message catalogs, you can use awk to convert to numeric:
d1=$(date | awk '{print $2*100 + $3}')
d2=$(ll $file | awk '{print $6*100 + $7}')
if [ $d1 -eq $d2 ]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2012 02:24 AM
02-13-2012 02:24 AM
Re: compare file's date with machine date
Oops that won't work since you have the month abbreviation. Try:
d1=$(date | awk '{print $2, $3 + 100}')
d2=$(ll $file | awk '{print $6, $7 + 100}')
if [ "$d" = "$d2" ]; then