Bash – Dynamic Public IP Address Monitor Script


This is a script I wrote to monitor my public IP address to see if it changes or not. It comes in very handy if you run a server on a dynamic IP address. It is setup to run in a daily cron job every morning. The script sends an email that lets me know if the IP address has changed or not, and also reports the current public IP address. Note that this script requires that curl is installed.


#Script to report public IP address change
#By: Ronny L. Bull


#The file that contains the current pubic IP

#Get the current public IP from

#Check file for previous IP address
if [ -f $EXT_IP_FILE ]; then

#See if the IP has changed
if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then

#If so send an alert
echo "Subject: The IP Address at home has changed
The IP address at home has been changed to $CURRENT_IP" | sendmail -f ${FROM} ${TO}

logger -t ipcheck -- IP changed to $CURRENT_IP

#If not just report that it stayed the same
echo "Subject: The IP Address at home is the same
The IP address at home stayed the same $CURRENT_IP" | sendmail -f ${FROM} ${TO}
logger -t ipcheck -- NO IP change

4 Responses to “Bash – Dynamic Public IP Address Monitor Script”

  1. Gus Hauptfleisch

    many thanks Ronny,
    I have plagiarised it and put it to use.
    Sending out as required.

  2. Bash script to send public IP address to Email | WebSetNet

    […] Credit goes to Ronny Bull – […]

  3. richard

    hello sir.thank you very much.
    please my question is how can i send this as email or execute this.
    in other words how do i use it or put this to work?
    is it going to ask me to click and open the message in ma inbox ?
    how do i use it actually?
    thank you

  4. Ronny

    The script uses your systems sendmail function in order to send the message. You need to set up sendmail if it is not working. Check out this post for instructions on how to configure SSMTP to send mail from a Linux system: