Guest User

Untitled

a guest
Oct 14th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # external-ip.sh
  5. #
  6.  
  7. # Quick script to scrape the external IP address
  8.  
  9. # Variables
  10. PATH=/usr/bin:/bin
  11. logfile=/home/username/.ip_log
  12. url="http://ipecho.net/plain"
  13. old_ip=""
  14. current_ip=""
  15.  
  16. if [ ! -e $logfile ]; then
  17. touch $logfile
  18. fi
  19.  
  20. if [ -e $logfile ]; then
  21. if [ -s $logfile ]; then
  22. old_ip=$(cat $logfile)
  23. current_ip=$(curl -s $url)
  24. if [ $old_ip = $current_ip ]; then
  25. exit 0;
  26. else
  27. echo $current_ip > $logfile
  28. echo 'New IP address for' `hostname -f` 'is:' $current_ip 'on' `date` | mail -s 'New IP' $email
  29. fi
  30. else
  31. current_ip=$(curl -s $url)
  32. echo $current_ip > $logfile
  33. fi
  34. fi
Advertisement
Add Comment
Please, Sign In to add comment