Giter Site home page Giter Site logo

ddnsupcheck.sh's Introduction

ddnsupcheck.sh

ShellCheck

Automatically checks if your public IP has changed, and if so it verifies if your DDNS record has been updated accordingly.

Contents

What is this?

This script is intended to run periodically (with a cronjob) to check if the public IP address of the machine has changed, and if so it checks if your custom DDNS record was updated accordingly. Without further customization it just logs these events under a file named log.txt and keeps an history of the IP addresses under ip_history.txt.

How does it work?

The first time the script runs it will create a file named lastrun_ip.txt where it will store your current public IP address (retrieved with curl https://ipinfo.io/ip). This file will be used in the next runs to check if there was an IP change.

Then at each next run the behavior will vary:

  1. The public IP address didn't change since last time: an event of severity INFO is logged.

  2. The public IP address has changed, but the DDNS record was updated accordingly: the new IP address is saved with a timestamp in the file ip_history.txt and an event of severity WARN is logged. You could add a custom action inside the if block, e.g. to send you a notification or make an API call.

  3. The public IP address has changed, and the DDNS record doesn't match the new IP: an event of severity CRIT is logged. You could add a custom action inside the if block, e.g. to update the record or send you a notification.

  4. The curl command fails (e.g. lack of connectivity): an event of severity CRIT is logged.

  5. The dig command fails (e.g. wrong dns record): an event of severity CRIT is logged.

Prerequisites

You won't need much. Your system must be able to run dig and curl, which shouldn't be a problem on any distro. Your firewall (if any) should allow traffic to https://ipinfo.io, used to retrieve your public IP address.

Installation

  1. Download ddnsupcheck.sh from the main branch to your local machine:
wget https://raw.githubusercontent.com/EarlyOwl/ddnsupcheck.sh/main/ddnsupcheck.sh
  1. Make it executable:
chmod +x ddnsupcheck.sh
  1. Open the script with your editor of choice:
nano ddnsupcheck.sh
  1. Edit the following variables to fit your needs:
#Your DDNS record to check
ddnsrecord="yourddnsrecord.example.com"

#Path for writing logs and other files. Default is current directory
workpath="."

#Timestamp used for logging. The default format is dd/mm/yyyy#h:m:s
timestamp=$(date +%d/%m/%y@%H:%M:%S)
  1. You can run the script manually with:
./ddnsupcheck.sh

But it would be better to set up a cronjob, for example to run each 5 minutes:

*/5 * * * * ./path/to/script/ddnsupcheck.sh
  1. (Optional) - Add some custom actions inside the if blocks of the script, e.g. sending a notification, updating the record, etc...

Misc

Can I contribute? Can I reuse all/part of this script for other purposes?

Yes and yes.

This sucks / You could have done X instead of X!

I'm eager to learn, open an issue or a pull request to suggest an improvement / fix.

ddnsupcheck.sh's People

Contributors

earlyowl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.