如何设置Pushover服务以告诉我Pi何时关闭或启动?


9

我想设置我的Raspberry Pi,以通过Pushover服务的curl API告诉我它何时打开或关闭。有哪些步骤可以做到这一点?

这是我在阅读问题时提出的。

Answers:


8

许多发行版,包括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

参考文献

  1. 如何在启动时加载模块?
  2. 如何在命令行上访问发行版的名称?
  3. 前推
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.