#!/bin/sh # # /usr/local/bin/myip # # This script displays the machine's current IP address # as well as options to save it in a log file and show the # last (old) IP log entry. if=eth0 # interface to check (change this if it's wrong) iplog=/var/log/myip.log usage() { echo "$0: print my IP address for a link" echo "USAGE: $0 [-p][-l]" >&2 echo "where: -p show previous address" >&2 echo " -l print IP address log" >&2 echo " -w write the new IP address to the log" >&2 } case "$1" in -p) tail -1 $iplog | awk '{print $NF}' ;; -l) cat $iplog ;; -w) echo `date` `$0` >>$iplog ;; -?|-h) usage ;; *) /sbin/ifconfig $if | awk '/inet addr:/ { ip=substr($2,6); print ip }' ;; esac