Wake-On-LAN Automation - BASH Script - RaspberryPi

Wake-On-LAN (WOL) is a very useful feature if you have got a LAB at home and want to make it energy efficient. I have written a small BASH script to automate the Wake-On-LAN (WOL) procedure which can be used in an instance where there is a ESXi server which can turned on as and when required and then shutdown when not needed. Believe me it saves a lot on electric bills as the Servers are not running 24/7 and powered on only when required.

Make sure you install WOL package on your RaspberryPi by running the below command.

# apt-get install wakeonlan

The below script will work as follows.

Check the status of the host via PING ("hppl-1" is the hostname)

If available then send a message its already powered ON.

If not,then send a wakeonlan command to the mac address of the host.

Wait 3 Minutes (sleep)

Again check the status og the host using PING.

If available, then send a message on the screen displaying its now powered ON.

If PING fails then send a message on the screen its failed and to check the network connections.