Skip to content

Instantly share code, notes, and snippets.

@tonythomas01
Last active January 22, 2024 08:23
Show Gist options
  • Save tonythomas01/74c901a3b52862d23e193550f4c2ef34 to your computer and use it in GitHub Desktop.
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
#!/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
# 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