Reboot message: Difference between revisions

From Coolscript
Jump to navigation Jump to search
(Created page with "Sample Reboot message: #!/bin/bash ipaddr=$(/usr/bin/curl --connect-timeout 1 --silent ipconfig.io) Hostname=`hostname` NOW=$( date '+%F_%H%M%S' ) #Dealing with telegram...")
 
No edit summary
Line 20: Line 20:
     --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"
/bin/sleep 10
/bin/sleep 10
/bin/echo "Reboot message" | /usr/bin/mail -s "Info: xxxx2 has been rebooted $MESSAGE" user@domain.com
/bin/echo "Reboot message" | /usr/bin/mail -s "Info: xxxx2 has been rebooted $MESSAGE" user@domain.com
 
*Unit file: /etc/systemd/system/reboot-msg.service
 
[Unit]
Description=MK Reboot Message
After=sendmail.service
[Service]
Type=oneshot
ExecStart=/usr/sbin/mkreboot-message.sh
[Install]
WantedBy=multi-user.target

Revision as of 20:55, 12 November 2022

Sample Reboot message:

#!/bin/bash
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
TELEGRAM_CHAT_ID="xxx"
TELEGRAM_BOT_TOKEN="xxxx"
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"
/bin/sleep 10
/bin/echo "Reboot message" | /usr/bin/mail -s "Info: xxxx2 has been rebooted $MESSAGE" user@domain.com
  • Unit file: /etc/systemd/system/reboot-msg.service
[Unit]
Description=MK Reboot Message
After=sendmail.service

[Service]
Type=oneshot
ExecStart=/usr/sbin/mkreboot-message.sh

[Install]
WantedBy=multi-user.target