How to enable wake-on-lan on your Western Digital NAS
The problem
I have a WD My Cloud EX2 Ultra, which overall is a good product, but because it is made for basic users, it lacks features and freedom. They allow you to access the device using SSH, but they don’t let you change anything. Basically, all the changes you make will be lost as soon as you reboot your device. Every time you turn your device off, the script that is executed is /usr/local/modules/script/shutdown.sh
. One of the conditionals in this script was supposed to enable wake-on-lan.
if [ -e /usr/sbin/set_wol ]; then
set_wol
fi
Although the result of this conditional is always true and the command set_wol
is executed, for some reason, it doesn’t enable WOL.
Solution
The fix this problem I created a script and a shortcut that enables WOL and then turns my NAS off. You can do the same thing on Windows using plink), but I will only demonstrate it on Linux.
Let’s get started
On your profile directory, create a file with only the sshd user password inside. In this case I created the file wd_pass. You can use the option -p
instead of -f
. Neither methods are perfect but -f
prevents your password from being saved in your commands history. Now create a file wd_off.sh with the content below changing the interface name and IP to fit yours.
#! /bin/bash
timeout 40 sshpass -f wd_pass ssh sshd@10.0.0.50 'ethtool -s egiga0 wol g && /usr/sbin/shutdown.sh'
chmod 750 wd_off.sh wd_pass
Time to create a shortcut on Gnome applications
First, download a SVG icon and save it as wd_icon.svg. Now, with root, paste the commands below in your terminal:
launch="#! /usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Exec=~/wd_off.sh
Name=Turn Off NAS
Icon=~/wd_icon.svg
Categories=Storage;Disk;"
echo "$launch" > /usr/share/applications/wd_off.desktop
Done. To turn on your NAS every time you login on your computer, with your user, run the command below on your PC replacing the MAC with your NAS MAC:
echo "/usr/bin/wol 00:14:ee:67:65:bf -p 7" >> ~/.bash_profile