I am trying to do a one time check about apache's mod-status page for updates like this(this is just a test script):
firstcontent=$(lynx -dump http://some-server/server-status-page)
echo $firstcontent > /tmp/myfirstcontentfiles.txt
nextcontent=$(lynx -dump http://some-server/server-status-page)
prevcontent=`cat /tmp/myfirstcontentfiles.txt`
#this always returns false, but their contents are same
if [ "$prevcontent" == "$firstcontent" ]; then echo "match"; fi
#but this returns true
if [ "$nextcontent" == "$firstcontent" ]; then echo "match"; fi
My question is why $prevcontent and $firstcontent comparision returns false whilst I am supposed to get a true return value? is anything happening behind the scene when I am saving it in a file?
echo $firstcontent > /tmp/myfirstcontentfiles.txt
. They'll get replaced by blanks. Tryecho "$firstcontent" > /tmp/myfirstcontentfiles.txt
instead. – Mark Plotnick Dec 24 '14 at 21:13$firstcontent
on the second line should fix your bug as @Mark says. I don't recommend storing the downloaded data in shell variables though. Instead, try downloading directly to a file and using thecmp
command to compare. Also consider usingwget
orcurl
for better portability. – Graeme Dec 24 '14 at 22:34diff
for comparing the two files. – steviethecat Dec 24 '14 at 22:44