Reboot message: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
*Script: /usr/sbin/reboot-message.sh | *Script: /usr/sbin/reboot-message.sh | ||
#!/bin/bash | #!/bin/bash | ||
TELEGRAM_CHAT_ID="xxx" | |||
TELEGRAM_BOT_TOKEN="xxxx" | |||
ipaddr=$(/usr/bin/curl --connect-timeout 1 --silent ipconfig.io) | ipaddr=$(/usr/bin/curl --connect-timeout 1 --silent ipconfig.io) | ||
Hostname=`hostname` | Hostname=`hostname` | ||
Line 7: | Line 9: | ||
#Dealing with telegram messages at login | #Dealing with telegram messages at login | ||
export LANG=C | export LANG=C | ||
MESSAGE="$(echo "<strong>Reboot Notification</strong> | MESSAGE="$(echo "<strong>Reboot Notification</strong> | ||
IP: $ipaddr | IP: $ipaddr | ||
Line 21: | Line 21: | ||
--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" | ||
*Unit file: /etc/systemd/system/reboot-msg.service | *Unit file: /etc/systemd/system/reboot-msg.service | ||
[Unit] | [Unit] | ||
Description= | Description=Reboot Message | ||
After= | Wants=network.target network-online.target | ||
After=network.target network-online.target | |||
[Service] | [Service] | ||
Line 36: | Line 36: | ||
[Install] | [Install] | ||
WantedBy=multi-user.target | WantedBy=multi-user.target | ||
Keys: reboot message |
Latest revision as of 23:30, 20 January 2023
Sample Reboot message:
- Script: /usr/sbin/reboot-message.sh
#!/bin/bash TELEGRAM_CHAT_ID="xxx" TELEGRAM_BOT_TOKEN="xxxx" ipaddr=$(/usr/bin/curl --connect-timeout 1 --silent ipconfig.io) Hostname=`hostname` NOW=$( date '+%F_%H%M%S' ) #Dealing with telegram messages at login export LANG=C MESSAGE="$(echo "Reboot Notification IP: $ipaddr Host: $Hostname Date: $NOW ")" logger "Debug 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"
- 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
Keys: reboot message