Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # external-ip.sh
- #
- # Quick script to scrape the external IP address
- # Variables
- PATH=/usr/bin:/bin
- logfile=/home/username/.ip_log
- url="http://ipecho.net/plain"
- old_ip=""
- current_ip=""
- if [ ! -e $logfile ]; then
- touch $logfile
- fi
- if [ -e $logfile ]; then
- if [ -s $logfile ]; then
- old_ip=$(cat $logfile)
- current_ip=$(curl -s $url)
- if [ $old_ip = $current_ip ]; then
- exit 0;
- else
- echo $current_ip > $logfile
- echo 'New IP address for' `hostname -f` 'is:' $current_ip 'on' `date` | mail -s 'New IP' $email
- fi
- else
- current_ip=$(curl -s $url)
- echo $current_ip > $logfile
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment