Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

file date verses current date

SOLVED
Go to solution
Highlighted
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
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