View Single Post

  #4 (permalink)  
Old 07-13-2007, 01:52 PM
Ali_ix's Avatar
Ali_ix Ali_ix is offline
Junior Member
User
 
Join Date: Jul 2007
Location: Iran, Tehran
My distro: Debian/Ubuntu
Posts: 6
Rep Power: 0
Ali_ix is on a distinguished road
Send a message via Yahoo to Ali_ix
Default

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.
Reply With Quote