Example usage from bash terminal:
./control.sh "wake"
./control.sh "sleep"
Requirements:
1) apt-get install etherwake sshpass fping
2) Make sure Wake on LAN is enabled in the PC's BIOS
3) Setup OpenSSH server on the Windows 10 PC.
control.sh
Code: Select all
#!/bin/bash
# Windows 10 PC Configuration
ip=""
mac=""
username=""
password=""
# Send WOL packet to PC (and repeat for up to 10 seconds if unable to ping the IP)
if [[ $1 == 'wake' ]]; then
wakeonlan "$mac" && timeout 10 bash -c -- "until fping -c1 -b 32 -t1000 $ip &>/dev/null; do wakeonlan $mac ; done"
elif [[ $1 == 'sleep' ]]; then
timeout 5s sshpass -p "$password" ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=no "$username"@"$ip" 'powercfg -h off & rundll32.exe powrprof.dll,SetSuspendState 0,1,0'
fi
Code: Select all
commandArray = {}
if (devicechanged["Desktop PC"] == 'On') then
os.execute ("/root/scripts/pcpowercontrol/control.sh 'wake' &")
end
return commandArray
- See last device to wake the pc: powercfg -lastwake
- See list of devices allowed to wake the pc: powercfg -devicequery wake_armed
- Disable a device from being allowed to wake the pc: powercfg -devicedisablewake "DEVICE_NAME"
Notes:
1) The command disables Windows 10 hibernation before issuing the sleep command (I want the Windows 10 PC to sleep, not hibernate)
2) SSH certificate verification is disabled which may be a security concern in some situations. You can easily enable it by changing "StrictHostKeyChecking=no" to "StrictHostKeyChecking=yes"