42 lines
846 B
Bash
42 lines
846 B
Bash
#! /bin/sh
|
|
# chkconfig: 2345 20 80
|
|
|
|
### BEGIN INIT INFO
|
|
# Provides: sendtelegram-reboot
|
|
# Required-Start: $all
|
|
# Required-Stop:
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop:
|
|
# Short-Description: Sending a message on startup
|
|
### END INIT INFO
|
|
|
|
start() {
|
|
APIURL="$(cat /usr/local/bin/sendtelegram.config | grep "APIURL=" | cut -d= -f2)"
|
|
CHATID="$(cat /usr/local/bin/sendtelegram.config | grep "CHATID=" | cut -d= -f2)"
|
|
TXTMSG="[System States] $(cat /etc/hostname): computer has been rebooted"
|
|
|
|
sleep 15
|
|
curl -s -X POST $APIURL -d chat_id=$CHATID -d text="$TXTMSG" >> /dev/null 2>&1 &
|
|
}
|
|
|
|
stop() {
|
|
pkill -f curl -s -X POST $APIURL
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
start
|
|
;;
|
|
stop)
|
|
stop
|
|
;;
|
|
restart)
|
|
stop
|
|
start
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart}"
|
|
esac
|
|
|
|
exit 0
|