Advertisement
Guest User

Untitled

a guest
May 25th, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.57 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. IP=$(curl -s http://www.ipchicken.com/ | awk '/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/ {print $1}' | uniq)
  4. FILE="/dev/shm/ip.dat"
  5.  
  6. trigger_notification () {
  7.   echo $IP > $FILE
  8.   # see http://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/
  9.   /sbin/ifconfig | mail -s "Notification: IP address $IP" my-email@addr.com
  10. }
  11.  
  12. if [ ! -f "$FILE" ]; then
  13.   # data file does not exist, create one and notify the user
  14.   trigger_notification
  15. else
  16.   if [ $IP != "$(cat $FILE)" ]
  17.   then
  18.     # file already exists but ip doesn't match
  19.     trigger_notification
  20.   fi
  21. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement