Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General > Member Success Stories
User Name
Password Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.


  Search this Thread
Old 07-02-2017, 11:31 PM   #1
Registered: Dec 2016
Distribution: Devuan+lxde
Posts: 639

Rep: Reputation: 189Reputation: 189
Simple bash script to check current ip and email new ip if changed

Hello all,
I've been creating various scripts to hone my scripting skills so I thought I'd share this here. It's just a simple bash script to check current ip address and, if it has changed, email the new current ip to specified address. You may need to create a couple empty files if they don't yet exist. (e.g. currentip.txt and oldip.txt) I may add in a test to check for existence and create if necessary at a later date.

Note that you will need to change /PATH/TO/SCRIPT to the proper location

DIFF=$(diff /PATH/TO/SCRIPT/currentip.txt <(echo "$IP"))
if [ "$IP" ]

    if [ "$DIFF" = "" ]
    elif [ "$DIFF" != "" ]
        mv /PATH/TO/SCRIPT/currentip.txt /PATH/TO/SCRIPT/oldip.txt        
        echo "$IP" >/PATH/TO/SCRIPT/currentip.txt
        mail -s "SUBJECT" YOUREMAIL@EXAMPLE.COM < /PATH/TO/SCRIPT/currentip.txt
Any questions, edits/suggestions are welcome

Last edited by TheEzekielProject; 07-02-2017 at 11:37 PM.


bash, email, ip, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Check status of a command in bash script and send email alert bmxakias Linux - Server 9 11-13-2016 07:29 AM
[SOLVED] Bash script to check if file is present or not, check periodically every 30 mins Iyyappan Linux - Server 10 07-03-2013 06:19 AM
[SOLVED] Bash script to check inodes and Email eyanu Linux - Newbie 10 09-25-2012 04:45 PM
Bash script to check if process is running and send email depam Linux - Newbie 2 04-08-2009 01:11 AM
Need help with script for check for a file that has changed in the last minute EclipseAgent Programming 10 02-12-2009 08:46 PM > Forums > Linux Forums > Linux - General > Member Success Stories

All times are GMT -5. The time now is 11:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration