Skip to content

Instantly share code, notes, and snippets.

Created June 20, 2017 03:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ferstar/6ebad5e70e17a9f4c05dabed7bf79d7b to your computer and use it in GitHub Desktop.
change switch ip when it changes
NOW_IP=$(ifconfig wlan0 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)
OLD_IP=$(jq -r '.switches[0].ip' ${SW_FILE})
if [ ${NOW_IP} != ${OLD_IP} ]; then
echo "ip changes detected, I'll update the ${SW_FILE}"
jq --arg v ${NOW_IP} '.switches[0].ip=$v' ${SW_FILE} > /tmp/tmp.json
mv /tmp/tmp.json ${SW_FILE}
echo "change ip from ${OLD_IP} to ${NOW_IP}"
echo "nothing to be done"
Copy link

ferstar commented Jun 20, 2017

check ip every 5 minutes by using the cron function.

crontab -e
*/5 * * * * /root/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment