storskogen
June 19th, 2009, 11:27 AM
I can't get my script to run as i want. It always executes the lines with email.
What have i missed? It should only email me if the IP is changed.
#!/bin/bash
# zddc.sh - Zoneedit.com Dynamic Dns Corrections.
#Created by Crouse
#05-15-2007
#Edit the next 3 lines
website="x.com"
zoneeditusername="xxxxxx"
zoneeditpassword="xxxxxx"
email=y@x.com
#Update IP address function, corrects settings on zoneedit.com
updateip ()
{
#Change entry for url with the x. prefix
wget -q -O - --http-user="${zoneeditusername}" --http-passwd="${zoneeditpassword}" "http://dynamic.zoneedit.com/auth/dynamic.html?host=x.${website}" > /dev/null 2>&1
#Change the entry for the url without the www. prefix
wget -O - --http-user="${zoneeditusername}" --http-passwd="${zoneeditpassword}" "http://dynamic.zoneedit.com/auth/dynamic.html?host=${website}" > /dev/null 2>&1
}
#Determine the current real ip address for this machine.
actualip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g'`
#Read in the current ip from currentip log file. Assign that value to a variable for comparison.
currentip=`less /home/$USER/.zoneedit`
#Output to display .... could echo it all to an email if setup as a cron job.
echo " "
echo "Zoneedit.com Update Check"
echo "The actual IP is: " $actualip
echo "The current IP is: " $currentip
if [ "$actualip" == "$currentip" ] ; then
echo "The IP's match, nothing to do, exiting."
echo " "
else
echo "IP's do not match"
echo "Updating the zone edit file." ; updateip
echo "Updating the .zoneedit file locally."
echo $actualip > /home/$USER/.zoneedit
echo "ZoneEdit update completed."
echo " "
echo " " | /usr/sbin/ssmtp $email < .zoneedit
fi
What have i missed? It should only email me if the IP is changed.
#!/bin/bash
# zddc.sh - Zoneedit.com Dynamic Dns Corrections.
#Created by Crouse
#05-15-2007
#Edit the next 3 lines
website="x.com"
zoneeditusername="xxxxxx"
zoneeditpassword="xxxxxx"
email=y@x.com
#Update IP address function, corrects settings on zoneedit.com
updateip ()
{
#Change entry for url with the x. prefix
wget -q -O - --http-user="${zoneeditusername}" --http-passwd="${zoneeditpassword}" "http://dynamic.zoneedit.com/auth/dynamic.html?host=x.${website}" > /dev/null 2>&1
#Change the entry for the url without the www. prefix
wget -O - --http-user="${zoneeditusername}" --http-passwd="${zoneeditpassword}" "http://dynamic.zoneedit.com/auth/dynamic.html?host=${website}" > /dev/null 2>&1
}
#Determine the current real ip address for this machine.
actualip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | awk '{ print $4 }' | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g'`
#Read in the current ip from currentip log file. Assign that value to a variable for comparison.
currentip=`less /home/$USER/.zoneedit`
#Output to display .... could echo it all to an email if setup as a cron job.
echo " "
echo "Zoneedit.com Update Check"
echo "The actual IP is: " $actualip
echo "The current IP is: " $currentip
if [ "$actualip" == "$currentip" ] ; then
echo "The IP's match, nothing to do, exiting."
echo " "
else
echo "IP's do not match"
echo "Updating the zone edit file." ; updateip
echo "Updating the .zoneedit file locally."
echo $actualip > /home/$USER/.zoneedit
echo "ZoneEdit update completed."
echo " "
echo " " | /usr/sbin/ssmtp $email < .zoneedit
fi