I've written a short script that pulls a line from /etc/sudoers (## Expires 12122012) on a remote host, and then compares it to today's date, using date +%d%m%Y. Even though both values appear the same when the variables assigned to them are dispalyed, the if statement never shows them as a match. The script and output are below. The extra echo statements are there to verify the variables actually matched.
#!/bin/bash
TODAY=`date +%d%m%Y`
EXPIRES=`ssh -t hostname "grep Expires /etc/sudoers"`
EXPIREDATE=`echo $EXPIRES | awk -F " " '{ printf $3 }'`
if [ $TODAY = $EXPIREDATE ]
then
echo "This matches"
exit
else
echo "this doesn't match"
echo "$TODAY"
echo "$EXPIREDATE"
exit
fi
exit
output: sh test
this doesn't match
12122012
12122012
I've tried multiple variations of the comparison but no luck. Any ideas are appreciated. Thanks!
UPDATE
After applying some suggestions from the comments for checking for white space, I'm able to see a bit more with the echo statements. Not quite sure how this is occuring 0_o
#>echo test${TODAY}more
test12122012more
#>echo test${EXPIREDATE}more
more12122012
if [ "$TODAY" = "$EXPIREDATE" ].cat thing | od -c?echo "$TODAY", printecho "test${TODAY}test", which will show you the whitespace."test${EXPIREDATE}foo", the output would befoot1212...:)test12122012word word12122012