Re: file date verses current date (140 Views)
Reply
Occasional Contributor
Peter Lyons_1
Posts: 8
Registered: ‎02-23-1999
Message 1 of 5 (140 Views)
Accepted Solution

file date verses current date

I haven't done many (hardly any) scripts and am getting frustrated with what should be an easy one. Can some of you more experienced script writes tell me what I'm doing wrong? What I am doing is trying to compare a file date with the current date.

#!/usr/bin/sh
CMDATE= date +'%b'
CDDATE= date +'%e'
FMDATE= ls -l TUXLOG.061002 | cut -c 46-48
FDDATE= ls -l TUXLOG.061002 | cut -c 50-52
print "Month: "$CMDATE "Day: "$CDDATE
print "Month: "$FMDATE "Day: "$FDDATE
if [[ "$CMDATE" -eq "$FMDATE" ]]
then
if [[ "$CDDATE" -eq "$FDDATE" ]]
then
print "They match"
else
print "Check Date"
fi
else
print "Check Date"
fi
exit
Esteemed Contributor
John Meissner
Posts: 887
Registered: ‎07-01-2002
Message 2 of 5 (140 Views)

Re: file date verses current date

d=$(date | awk '{print $2,$3}')
file=filename
d2=$(ls -la $:file | awk '{print $6,$7}')
if [ "$d" = "$d2" ]
then
echo "they match"
elif [ "$d" != "$d2" ]
then
echo "Check date"
fi
All paths lead to destiny
Esteemed Contributor
John Meissner
Posts: 887
Registered: ‎07-01-2002
Message 3 of 5 (140 Views)

Re: file date verses current date

you'll have to excuse my fat fingers.....
d2=$(ls -la $:file | awk '{print $6,$7}')

should read d2=$(ls -la $file | awk '{print $6,$7}')

I put a : in accidently
All paths lead to destiny
Occasional Contributor
Peter Lyons_1
Posts: 8
Registered: ‎02-23-1999
Message 4 of 5 (140 Views)

Re: file date verses current date

Thanks that did the trick!
Esteemed Contributor
John Meissner
Posts: 887
Registered: ‎07-01-2002
Message 5 of 5 (140 Views)

Re: file date verses current date

great - I'm glad to hear that. I started scripting about a year ago - just a little after I started using Unix/Linux.
If you're frustrated I can recomment 2 books that have helped me tremendously:

Korn Shell Programming
by O'Brien, Pitts
and
sed & awk
O'Reilly
All paths lead to destiny
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.