I've recently become an AT&T Broadband Internet customer, sacrificing my
static IP address with DSL to avoid the beast that is Qworst.  Since, I
like to ssh into my workstation every now and then, I am presented with
the challenge of knowing what my IP address might be.  

As with all DHCP setups, your computer may lease an IP address
indefinitely, but there is always the chance that the DHCP server will
allocate the address to someone else and give you a new one.  What was
my answer?  With `ip', `shell', `sed', and `sendmail', I created a
script that updates me whenever the IP address to my NIC changes.

For those unfamiliar w/ip, it is the advanced routing tool, and an
effective replacement to ifconfig.  This script could be adapted to
ifconfig quite easily.

I was trying to think of a way to speed it up by perhaps removing the
need to use `cat' and `hostname'.  The absolute paths for binaries are
used for this purpose, too; speed.  The shell doesn't have to search
PATH for the binaries before executing them.

Enjoy!
^chewie

#################### BEGIN SCRIPT ###################################
#!/bin/sh
#
# Print the ipv4 address of an interface
#
# Full paths for executables are provided for speed so that the shell doesn't
# need to search PATH for the files.
ip="/sbin/ip"
sed="/bin/sed"
cat="/bin/cat"
sendmail="/usr/sbin/sendmail"

# DEFAULTS
IFACE=${IFACE:-"eth0"}
ADDR=${ADDR:-"username at domain.tld"}
USER=${USER:-"root"}

# Get the IP address for eth0
function getipv4() {
    iface="$1"
    $ip -4 address show $iface | $sed -e '/^.*inet/ !D' \
        -e 's/.*inet \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)\/.*/\1/'
}

##################
# main script body

# Process commandline options
[ $1 ] && IFACE=$1
[ $2 ] && ADDR=$2

# Send the message
$cat << EOMSG | $sendmail -oi -t
To: $ADDR
From: $USER
Subject: IP address for $IFACE on `hostname`

`getipv4 $IFACE`
EOMSG

#################### END SCRIPT ###################################

--
Chad Walstrom <chewie at wookimus.net>                 | a.k.a. ^chewie
http://www.wookimus.net/                            | s.k.a. gunnarr
Key fingerprint = B4AB D627 9CBD 687E 7A31  1950 0CC7 0B18 206C 5AFD