Scripts that I use on my Raspberry Pi #1

This script checks what your current external IP address and will let you know if it has changed since the last time you checked. You can easily modify this script to make your Raspberry Pi send you an email of it’s external IP address and send email when it’s email address has changed so this is pretty useful script for many kind of headless Raspberry Pi uses.

#!/bin/sh

ip1=""
ip2=""
ip="/scripts/ip.txt"

[ ! -f $ip ] && touch $ip

read ip1 < $ip
ip2=$(wget -U 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4' -qO- ifconfig.me/ip)



if [ "$ip1" = "$ip2" ]
then
 echo "IP is still the same $ip2"
  exit
else
  echo "$ip2" > $ip
        echo "IP has changed and it's now $ip2"
  exit
fi

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

This site uses Akismet to reduce spam. Learn how your comment data is processed.