Answers:
许多发行版,包括Arch和Debian / Raspbian,都使用初始化脚本来初始化系统,并且您可以使用它们来运行任意命令。您需要在中安装类似于以下内容的脚本/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
您应该向Pushover服务注册,然后在TOKEN
变量中输入您的应用令牌,并在变量中输入用户密钥USER
。
首先在您的主目录中对其进行测试,然后将其移至/etc/init.d/pushover
。您应该确保它是可运行的并且由root拥有。
sudo chmod 755 /etc/init.d/pushover
sudo chown root:root /etc/init.d/pushover