thenadz

Send Text on Public IP Change (part 2)

May 20th, 2013
2,238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Before using, home directory references must be modified to match invoking user.
  4. # Additionally, run touch on ~/.ip-cache prior to first run to avoid issues.
  5.  
  6. cache='/home/rossiter/.ip-cache'
  7. prev=`/bin/cat $cache`
  8. current=`/usr/bin/wget -qO- http://ipecho.net/plain`
  9.  
  10. # trap possible wget error
  11. if [ $? != 0 ]; then
  12.    exit 1;
  13. fi
  14.  
  15. # new IP found
  16. if [ "$current" != "$prev" ]; then
  17.    /home/rossiter/bin/sms 12104584011 "$current"
  18.  
  19.    # SMS was successfully delivered to Google Voice
  20.    # (impossible to determine whether SMS was delivered to phone)
  21.    if [ $? -eq 0 ]; then
  22.       /bin/echo "$current" > "$cache"
  23.       exit 0
  24.  
  25.    # SMS send failed
  26.    else
  27.       exit 1;
  28.    fi
  29.  
  30. # old IP still present
  31. else
  32.    exit 0;
  33. fi
Advertisement
Add Comment
Please, Sign In to add comment