if statements and case statements not working in bourne shell script
Hello,
I run an ssh server for myself and a few friends, however with a dynamic ip it got annoying... so I found dyndns.org. My domain was locked for "abuse" when the scripot I download from them uipdated too much.
After spending a few hours going through the scripts and programs, I decided to write my own.
It works perfectly, expect for one thing. There is something wrong with the if statement. I changed it to a case statement and it still does not work.
This is the script:
#! /bin/bash
#####################################################
#
# dyndns updater /version 1.0
#
#####################################################
#Set variables
user=user
pass=pass
system=dyndns
host= <host>
wildcard=ON
#Get IP address and filter it
wget -O /root/dyndns/ip.html <URL removed.>
cat /root/dyndns/ip.html | grep Your | cut -b 20-35 > ip.cut
#Make IP address into shell variables.
newip=$(cat /root/dyndns/ip.cut)
oldip=$(cat /root/dyndns/ip.current)
#Compare the IPs to each other
case "$newip" in
'$oldip')
echo "IP is the same, not updating"
exit 0
;;
*)
echo $newip > /root/dyndns/ip.current
#curl -s -u $user:$pass <URL removed, system wouldn't let me post it>;;
esac
Before the case statement was an if statement that looked like this:
if [ $newip -eq $oldip ]
then
echo "IP is the same, not updating"
exit 0
else
echo $newip > /root/dyndns/ip.current
#curl -s -u $user:$pass "members.dyndns.org/nic/update?system=$system&hostname=$host&wildcard=$wildcard"
It always acts as if the newip and oldip variables are differant. but I've checked them, over and over, and it always tries to update (that's why the curl command is commented out, couldn't test it without getting banned otherwise.).
Can anyone tell me what is wrong here? Is there some concept I am totally not understanding, or something I am missing from staring at the shell for so long?
-Michael
|