Operating System - HP-UX
1745972 Members
4706 Online
108724 Solutions
New Discussion юеВ

Re: file date verses current date

 
SOLVED
Go to solution
Peter Lyons_1
Occasional Contributor

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
4 REPLIES 4
John Meissner
Esteemed Contributor
Solution

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
John Meissner
Esteemed Contributor

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
Peter Lyons_1
Occasional Contributor

Re: file date verses current date

Thanks that did the trick!
John Meissner
Esteemed Contributor

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