I have an adsl account that works through pppoe, this is my script:
Code:
#!/bin/bash
#set -x
IFACE=ppp0
EMAIL=you@domain
LOG=/your/log/path/ip
OLD_IP=`cat $LOG`
# get current ip on IFACE
x=`/sbin/ifconfig $IFACE`
y=${x#*inet addr:}
y=${y%% *}
# log current ip
echo $y > $LOG
# check if ip changed
# if we have disconnected for a long time
if [[ -z "$OLD_IP" ]] && [[ "$y" ]]; then
# report new ip
echo 'New IP address for' `hostname` 'is:' $y 'on ' `date` | mail -s 'New IP' $EMAIL
# if ip changed since last check
elif [[ "$OLD_IP" ]] && [[ "$y" ]]; then
if [ "$y" != "$OLD_IP" ]; then
# report new ip
echo 'New IP address for' `hostname` 'is:' $y 'on ' `date` | mail -s 'New IP' $EMAIL
fi
fi
exit 0
run it every 5 minute via cron.
