Last active
January 22, 2024 08:23
-
-
Save tonythomas01/74c901a3b52862d23e193550f4c2ef34 to your computer and use it in GitHub Desktop.
Bash script to post to Telegram bot when your machine IP address change #telegram #ip #bot
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
#!/usr/bin/env bash | |
# Script stores the current IP in a tmp file and later checks if it changed when run. POSTS to a Telegram bot. | |
# Check how you can create a bot at https://core.telegram.org/bots | |
old_ip=`cat /tmp/currentip` | |
current_ip=`wget -qO- https://ipecho.net/plain` | |
if [ $current_ip != $old_ip ]; then | |
curl -s -X POST https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/sendMessage -d chat_id=<CHAT_ID> -d text="Machine changed IP from: ${old_ip} to ${current_ip}" | |
wget -qO- https://ipecho.net/plain > /tmp/currentip | |
fi |
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
# Run every hour at hour:05 k | |
5 * * * * /Users/path/notify_telegram_bot_ip.sh &>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment