# 4. Location
basedir="/usr/local/pingcard"
basefile="$basedir/oldcardIP"
# 5. What jobs is your needed?
# 1. e-mail and re-dial up
jobs="1"
#######################################################################
#====================== DETECT FILES SESSION ==========================
# 1. Detect the lynx package.
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH
if [ "$jobs" == "2" ] || [ "$jobs" == "3" ]; then
which lynx > /dev/null 2>&1
if [ "$?" != "0" ]; then
echo "The nessecery package ==> lynx do not install!"
echo "lease install this package before running this."
exit 1
fi
fi
# 2. Detect the old IP file
if [ ! -f $basefile ]; then
echo $welcome | mail -s "Welcome using ping_net_card.sh" \
$emailto
/bin/touch $basefile
fi
#######################################################################
#====================== Functions =====================
# Get the NEW IP.
oldip () {
oldip=`cat $basefile`
}
getip () {
ifconfig "$outif" > /dev/null 2>&1
if [ "$?" == "0" ]; then
newip=`ifconfig "$outif" | grep 'inet' | \
awk '{print $2}' | sed -e "s/addr\://"`
else
newip=""
fi
}
# Check IP
checkip () {
if [ "$method" == "adsl" ]; then
adsl-stop > /dev/null 2>&1
sleep 3s
adsl-start > /dev/null 2>&1
fi
if [ "$method" == "cable" ]; then
ifdown $nicif > /dev/null 2>&1
sleep 3s
ifup $nicif > /dev/null 2>&1
fi
sleep 3s
}
# Email the new IP to Admin
mailtoyou () {
echo $newip | \
mail -s "The new IP in your $hostname" $emailto
echo "$newip" > $basefile
}
#
#====================== ONLY EMAIL SESSION jobs 1 =====================
if [ "$jobs" == "1" ]; then
# 1. Get the older IP and newer IP
oldip
getip
while [ "$newip" == "" ]
do
checkip
getip
done
# 2. compare with older IP and newer IP. And e-mail to you
if [ "$newip" != "$oldip" ]; then
mailtoyou # just mail to you
fi
exit 0
fi