linux上安装etherwake和samba-common远程控制windows开关机
前言
偶尔在外需要连到家里pc,但一直开机浪费电啊,所以用在家里24小时运行的linux服务器进行远程开关机管理。
wol唤醒
首先主板BIOS设置好网络唤醒,每个厂商都不一样这里就不多说了。
1
2
3
4
| #安装etherwake
apt install etherwake
#发送魔术包唤醒
wakeonlan MAC
|
关机和重启
1
2
3
4
5
6
7
8
9
10
| #安装samba-common
apt install samba-common
#关机
net rpc shutdown -I IPADDRESS -U USERNAME%PASSWORD -t 0
#600秒后关机
net rpc shutdown -I IPADDRESS -U USERNAME%PASSWORD -t 600
#重启
net rpc shutdown -I IPADDRESS -U USERNAME%PASSWORD -r
#取消关机
net rpc abortshutdown -I IPADDRESS -U USERNAME%PASSWORD
|
权限设置


脚本
为了方便我写了个shell脚本来执行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| #!/bin/bash
while [ -n "$1" ]
do
case "$1" in
start) wakeonlan F4:B5:20:0A:CC:BA
echo "start...";;
stop) time=$2
net rpc shutdown -I 192.168.1.3 -U HXF%password -t $time
echo "stop after $time seconds..."
shift ;;
restart) net rpc shutdown -I 192.168.1.3 -U HXF%password -r
echo "restart...";;
abort) net rpc abortshutdown -I 192.168.1.3 -U HXF%password
echo "abort...";;
*) echo "undefined option";;
esac
shift
done
|