Update IP to someone server

#!/bin/bash
#
# Written by Jeffrey
#
#

# set variables
if echo $0 | grep '^/' ; then
w_dir=${0%/*}
else
w_dir=$PWD/${0%/*}
fi

UPDATE_IP=$w_dir/oldip.dat
HOST_NAME=host1.com
MAILTO="name1@yahoo.com.hk"
#IF="eth0"
IF="ppp0"

# get current ip
NEWIP=$(ifconfig | grep "$IF " -A 1 | awk '/inet/ {print $2}' | sed -e 's/.*://')
OLDIP=$(cat $UPDATE_IP)
if [ "$NEWIP" != "$OLDIP" ]; then
echo $NEWIP > $UPDATE_IP
uptime | mail $MAILTO -s "[$HOST_NAME] ip changed to $(cat $UPDATE_IP)"
echo "$(date) [$HOST_NAME] ip changed to $(cat $UPDATE_IP)" >> /var/log/ipchange.log
fi

Comments

Popular Posts