, the easiest way would be grabbing the IP address
from the output of ifconfig
, which could be something like this (if the interface is ppp0):
/sbin/ifconfig | grep -A1 ppp0 | tail -1 | cut -d : -f 2 | cut -f 1 -d " "
If were talking about ppp, another way of doing it is getting the address from the ip-up script. On RedHat it is located in /etc/ppp/, but it might differ across distributions. I recommend creating a script called ip-up.local and have it output it's arguments somewhere. This script will be run automagically from ip-up that'll pass the IP address to it.
/etc/ppp/ip-up.local is passed the arguments interface, device, linespeed, IP address, remote IP address and for some reason the interface again. (I guess the last is an alias or something)
This would send an e-mail to root containing the IP address whenever a ppp-interface is up:
echo "IP address:$4" | mail -s "Woohoo" root@localhost
mentioned that the variable $LOCALIP in ip-up contains the address, but I like the above solution better, as ip-up.local won't be overwritten when you upgrade the ppp
package and ip-up will. But then, it's probably different on other distros.
You could also put DEBUG=yes in ifcfg-ppp0 (or whatever interface) and look in /var/log/messages.