Extract IP and monitor changes
Extract IP
This will extract the ip number (IPv4):
ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
Or this:
ifconfig eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
If you want IPv6:
ip -6 addr | grep -oP '(?<=inet6\s)[\da-f:]+'
Script
!/bin/bash
OLD_IP=cat ip.txt
NEW_IP=/sbin/ifconfig | awk -F "[: ]+'{ print $4}'
#adapted from something I got from the internets.
if [ $NEW_IP != OLD_IP ]; then
nsupdate