断电后,无人值守,需要在供电恢复时,自动唤醒主机。Ubnt EdgeRouter X 固件支持自启动脚本。
#!/bin/sh
# wake up app server
# send to all interfaces to prevent the network interface was replaced
for (( i = 1; i <= 4; i++ )); do
/usr/sbin/etherwake aa:bb:cc:dd:ee:ff -i eth$i
done
echo "[$(date '+%Y-%m-%d %H:%M:%S')] wake up signal was send to app server." > /var/log/wol_srv.log
# wait for another router to be ready
sleep 1s
# wake up NAS through another router
for (( i = 1; i <= 4; i++ )); do
ssh -i /home/mos/.ssh/id_rsa -p9922 mos@10.8.8.199 "/usr/sbin/ether-wake -i eth$i aa:bb:cc:dd:ee:ff"
done
同时,也可以其它任务,如执行远程命令。这里是向另一台接了 NAS 的路由器发送了网络唤醒指令。
为了避免执行 ssh host command 时要求输入密码,可以使用命令 ssh-copy-id 提前复制登录证书到远程主机。详细可以参考:
2、修改文件属性,添加可执行选项
chmod a+x 9900wol-srv
3、重启路由器即可自动执行。