Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

file date verses current date

SOLVED
Go to Solution
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
1 ACCEPTED SOLUTIONS
Esteemed Contributor Esteemed Contributor

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

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

Re: file date verses current date

Thanks that did the trick!
Highlighted
Esteemed Contributor 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