Câu trả lời:
Rất nhiều bản phân phối, bao gồm Arch và Debian / Raspbian, sử dụng initscripts để khởi tạo hệ thống và bạn có thể sử dụng chúng để chạy các lệnh tùy ý. Bạn cần cài đặt một tập lệnh tương tự như sau /etc/init.d
.
#! /bin/sh
# /etc/init.d/pushover
#
# Some things that run always
touch /var/lock/pushover
TOKEN=
USER=
DIST=`cat /etc/os-release | perl -n -e '/^NAME=\"([a-zA-Z ]*)\"$/ && print "$1\n"'`
echo $TOKEN
echo $USER
echo $DIST
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting script pushover "
curl -s \
--data-urlencode "token=$TOKEN" \
--data-urlencode "user=$USER" \
--data-urlencode "message=Raspberry Pi ($DIST) is starting." \
https://api.pushover.net/1/messages
;;
stop)
echo "Stopping script pushover"
curl -s \
--data-urlencode "token=$TOKEN" \
--data-urlencode "user=$USER" \
--data-urlencode "message=Raspberry Pi ($DIST) is stopping." \
https://api.pushover.net/1/messages
;;
*)
echo "Usage: /etc/init.d/pushover {start|stop}"
exit 1
;;
esac
exit 0
Bạn nên đăng ký với dịch vụ Pushover và nhập mã thông báo ứng dụng của bạn vào TOKEN
biến và khóa người dùng của bạn trong USER
biến.
Kiểm tra nó trong thư mục nhà của bạn đầu tiên, sau đó di chuyển nó đến /etc/init.d/pushover
. Bạn nên đảm bảo nó có thể chạy được và được sở hữu bởi root.
sudo chmod 755 /etc/init.d/pushover
sudo chown root:root /etc/init.d/pushover