You are not logged in.
Pages: 1
I am new to bash scripting so I am sorry if this is really easy. I want to check my internet IP and send it in an email to myself whenever it changes. I want to be able to connect to a few services on my computer while I am away and my ISP keeps changing my IP address so I will like a shell script that can run in the background to keep me up to date on my home box's latest IP address.
Is this something that is doable? If so could someone give me a push in the right direction. I read a few how-tos but I was hoping someone could suggest a good command line mailer that I can use with my gmail account and any other useful tips for a newbie.
Offline
Try 'curl ifconfig.me' & heirloom-mailx for scripting e-mail e.g.
curl ifconfig.me | mailx -s "my IP" login@gmail.comjust use your own e-mail address and of course you can change the subject of the e-mail to something other than "my IP".
You can run it via cron e.g. every hour.
Last edited by karol (2011-03-16 00:40:06)
Offline

Offline
Okay I think I can make the mail portion of that work just fine but ifconfig only gives me my local IP. After a little research I think I am going to use dig to get my outgoing IP.
Thanks for you help karol!
Offline
ifconfig only gives me my local IP.
I'm not sure if I got this right, but ifconfig.me is a website. I'm not talking about the ifconfig command.
Offline
xcrx wrote:ifconfig only gives me my local IP.
I'm not sure if I got this right, but ifconfig.me is a website. I'm not talking about the ifconfig command.
Oh okay. Sorry. I am not at home where I can try it out right now. My mistake.
Offline
you might want to consider a dynamic dns service like http://www.dyndns.com. I've been using them for a few years to do what you want to do.
emk
Offline

Another DNS service is http://freedns.afraid.org
There are many domains to choose from. Some are pretty funny too. Once you've setup the DNS look for the wget script, or direct link to update the DNS. Launch this script via cron every day or hour, depending how often the address changes.
Offline

I wrote a script to do just this.  It's in the AUR:
http://aur.archlinux.org/packages.php?ID=37553
Offline
my script for checking ip from conky
#! /bin/bash
#
# Automated script to retrieve public IP from whatismyip.com
cache=/tmp/`basename $0`
now=`date +%s`
update_int=400                          # 300 or less will get you banned
pattern='([0-9]{1,3}\.){3}[0-9]{1,3}'
doupdate () {
    # Could also try myip.dk, ifconfig.me
    addr=`curl -s http://www.whatismyip.com/automation/n09230945.asp`
    if [[ $? -gt 0 ]]
    then 
        echo 'No address' > $cache/addr
        echo 0          > $cache/time
    elif [[ `echo $addr | egrep $pattern` == '' ]]
    then
        echo 'Remote down' > $cache/addr
        echo 0          > $cache/time
    else
        echo $addr        > $cache/addr
        echo $now         > $cache/time
    fi
}
    
mkdir -p $cache
if [[ -f $cache/time ]]
then
    then=`cat $cache/time`            # Time of last update
    int=$(( $now - $then ))        
    if [[ $int -gt $update_int ]] 
    then
        doupdate
    fi
else
    doupdate
fi
echo `cat $cache/addr` # \(${int}s ago\)Offline
Pages: 1