Created
June 20, 2017 03:08
-
-
Save ferstar/6ebad5e70e17a9f4c05dabed7bf79d7b to your computer and use it in GitHub Desktop.
change switch ip when it changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| PATH=/usr/bin:/sbin:/bin | |
| SW_FILE=/www/switches.json | |
| 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}" | |
| else | |
| echo "nothing to be done" | |
| fi |
Author
Thank you, I added a link to your gist to the instruction https://github.com/yurt-page/Kankun_KK-SP3
Author
Thank you, I added a link to your gist to the instruction https://github.com/yurt-page/Kankun_KK-SP3
I'm extremely glad that a script I created so many years ago can still be useful! Thank you so much for adding a link to my gist in the instruction. It means a lot to me.
In fact it should be enough to configure router with a static IP by a MAC address or host name like kankun. I'll try to extend the instructions.
Author
In fact it should be enough to configure router with a static IP by a MAC address or host name like
kankun. I'll try to extend the instructions.
Actually, your method is even simpler.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
check ip every 5 minutes by using the cron function.