Extract IP Link to heading
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 Link to heading
#!/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 #it seems like the keys need to be in the same directory from where nsupdate was called
fi
echo $NEW_IP > ip.txt
exit 0 #not sure if this is necessary