Skip to content

Instantly share code, notes, and snippets.

@steveswing
Created June 15, 2019 04:19
Show Gist options
  • Save steveswing/c82c2f535ff4d5013207e9cc09600fbb to your computer and use it in GitHub Desktop.
Save steveswing/c82c2f535ff4d5013207e9cc09600fbb to your computer and use it in GitHub Desktop.
#!/bin/bash
# checkip.sh
# Detect when public IP address changes
# Add the following to the crontab (i.e. crontab -e)
# */30 * * * * ~/checkip.sh
# To successfully start SubstratumNode in privileged mode this script has to run as root or as a sudoer.
# When run by cron sudo can't prompt for a password. See creating /etc/sudoers.d/<username> and adding an entry like the following:
# %<your-user-here> ALL=(ALL) NOPASSWD:SETENV: /your/path/to/build/directory/node_ui/static/binaries/SubstratumNode
# Change paths ./recorded-ipv4 and SubstratumNode as needed for your system
currentIPv4=$(curl --silent 'https://api.ipify.org')
test -e ./recorded-ipv4 || echo $currentIPv4 > ./recorded-ipv4
previousIPv4=$(cat ./recorded-ipv4)
echo $currentIPv4 > ./recorded-ipv4
if [ "$previousIPv4" != "$currentIPv4" ]; then
echo Detected IPv4 Address change from $previousIPv4 to $currentIPv4. Retarting SubstratumNode...
pkill -f SubstratumNode
sleep 10
# the following requires sudo if not run as root
SubstratumNode
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment