用左Jason 個dns server
剛剛Jason 起左個dns server 所以我寫一個script 將我個ip 每次改的時候通知佢。
以下是script
#!/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=jktn.com
MAILTO="hello@yahoo.com.hk root"
#IF="eth0"
IF="ppp0"
# get current ip
NEWIP=$(ifconfig | grep "$IF " -A 1 | awk \'/inet/ {print $2}\' | sed -e \'s/.*://\')
OLDIP=$(cat oldip.dat)
if [ "$NEWIP" != "$OLDIP" ]; then
echo $NEWIP > oldip.dat
uptime | mail $MAILTO -s "[$HOST_NAME] ip changed to $(cat oldip.dat)"
fi
Comments