Last active
May 2, 2018 16:57
-
-
Save shi-yan/5e198ecf10b15de8e95fe8be7a0f4ffc to your computer and use it in GitHub Desktop.
My work machine changes IP, If I want to ssh into it from home, often I need to know its ip. This is the bash script to report ip change to my slack. Need to set cron job: crontab -e, 0 * * * * /home/xxx/reportip.sh
This file contains 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/bash | |
touch oldIp.txt | |
md1=$(cat "oldIp.txt"); | |
md2=$(hostname -I); | |
if [ "$md1" = "$md2" ]; then | |
echo The same | |
else | |
echo Different | |
hostname -I | |
cat oldIp.txt | |
hostname=$(hostname); | |
echo "{\"text\":\"ip of ${hostname} is ${md2}\"}" | curl -X POST -H 'Content-type: application/json' --data @- https://hooks.slack.com/services/xxx/xxx/xxx | |
hostname -I > oldIp.txt | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment