Reboot Message send to Telegram: Difference between revisions
Jump to navigation
Jump to search
(Created page with "How to send a Telegram Message uppon reboot *Create /usr/sbin/reboot-message.sh #!/bin/bash #Send a Telegram message on boot #--------------------------------- TELEGRAM_C...") |
No edit summary |
||
Line 1: | Line 1: | ||
How to send a Telegram Message uppon reboot | How to send a Telegram Message uppon reboot | ||
*Create /usr/sbin/reboot-message.sh | *Create the script: /usr/sbin/reboot-message.sh | ||
#!/bin/bash | #!/bin/bash | ||
#Send a Telegram message on boot | #Send a Telegram message on boot | ||
Line 24: | Line 24: | ||
--data-urlencode "disable_web_page_preview=true" \ | --data-urlencode "disable_web_page_preview=true" \ | ||
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" | "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" | ||
*Create the Systemctl unit file: /etc/systemd/system/reboot-msg.service | |||
[Unit] | |||
Description=Reboot Message | |||
Wants=network.target network-online.target | |||
After=network.target network-online.target | |||
[Service] | |||
Type=oneshot | |||
ExecStart=/usr/sbin/reboot-message.sh | |||
[Install] | |||
WantedBy=multi-user.target | |||
*Apply | |||
chmod 755 /usr/sbin/reboot-message.sh | |||
systemctl daemon-reload | |||
systemctl enable reboot-msg.service |
Revision as of 20:02, 20 January 2023
How to send a Telegram Message uppon reboot
- Create the script: /usr/sbin/reboot-message.sh
#!/bin/bash #Send a Telegram message on boot #--------------------------------- TELEGRAM_CHAT_ID="Your Chat ID" TELEGRAM_BOT_TOKEN="Your Bot Token" #--------------------------------- ipaddr=$(/usr/bin/curl --connect-timeout 1 --silent ipconfig.io) Hostname=`hostname` NOW=$( date '+%F_%H%M%S' ) export LANG=C MESSAGE="$(echo "Reboot Notification IP: $ipaddr Host: $Hostname Date: $NOW ")" logger "Debug Reboot Message" logger $MESSAGE /usr/bin/curl --connect-timeout 5 --max-time 10 --silent --output /dev/null \ --data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \ --data-urlencode "text=${MESSAGE}" \ --data-urlencode "parse_mode=HTML" \ --data-urlencode "disable_web_page_preview=true" \ "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage"
- Create the Systemctl unit file: /etc/systemd/system/reboot-msg.service
[Unit] Description=Reboot Message Wants=network.target network-online.target After=network.target network-online.target
[Service] Type=oneshot ExecStart=/usr/sbin/reboot-message.sh
[Install] WantedBy=multi-user.target
- Apply
chmod 755 /usr/sbin/reboot-message.sh systemctl daemon-reload systemctl enable reboot-msg.service