Here is the scenario, you are an independent IT consultant and/or an administrator of some business IT infrastructure. The systems you manage are a mix of Linux and Microsoft desktop and server systems. You do much of your system updates and other management tasks after hours using remote access over VNC or a VPN so you can be home with your family. The upper management, also know as “suits”, at your location has decided that shutting down PC desktop systems after hours is a great cost savings measure and tells you to implement a plan to do this. The suits also want the desktop PC systems to be up and running when employees arrive in the mornings so time is not wasted while people wait for their PC to start up. How do you do all this and still give yourself that time at home at night when you need to do those after hours management tasks? Enter Remote Wakeup, otherwise known as Wake on LAN.
I was presented with a challenge like this for one of our charity organization clients that is trying to cut costs as much as possible. The idea originally was that each PC will shut down each night after running its nightly backup. Then each morning the systems would be restarted by the users when they came in. Since most of the support provided by my company happens after hours this meant we needed to implement Wake on LAN so we could still provide that after hours support while giving the client the cost savings from shutting down the PC systems overnight. To do this we use the ‘wakeonlan’ Perl application with a mix of cron job and hand created scripts to wake up PC systems as needed. Each PC that needs to be awakened has its BIOS set with Wake on LAN enabled. One Linux PC system is set up as the “master” system for managing Wake on LAN and that PC is never shut down. That one PCs BIOS is configured to auto-restart that PC after a power outage so it will always be available.
Another hitch in this request is that some of the Windows desktop users do need access from home either after hours or over weekends. These people are completely unfamiliar with Linux and so need to be given an easy way to access the ‘wakeonlan’ capability of the Linux PC that handles this. This is accomplished by giving them PuTTY on Windows at home with a saved session that logs them into an account on the Linux PC over SSH. From there they just type ‘wol’ and are given a menu from which they can choose the PC they need to “wake up”. Here is a copy of the ‘wol’ script as it exists today:
#!/bin/bash # wol script by ERA Computers & Consulting www.eracc.com clear wolmenu="wol.menu" woldata="wol.data" wolloc="`dirname \"$0\"`/" if [ ! -f $wolloc$wolmenu ] then echo Cannot find my menu file. My files should be in $wolloc. elif [ ! -f $wolloc$woldata ] then echo Cannot find my data file. My files should be in $wolloc. else cat $wolloc$wolmenu echo;echo Type the number of the PC to awaken or c to cancel and press Enter: read n case $n in c) exit; ;; C) exit; ;; *) echo Waking up `grep ^$n $wolloc$wolmenu`.; ipsubnet=`grep ^$n $wolloc$woldata|cut -d ' ' -f 3`; hwaddress=`grep ^$n $wolloc$woldata|cut -d ' ' -f 2`; echo The command running is - wakeonlan -i $ipsubnet $hwaddress; wakeonlan -i $ipsubnet $hwaddress; ;; esac fi
There is more that could be done to check for invalid input and to check to see when a PC starts responding to pings, but this serves our needs just fine as it is written. The wol.menu and wol.data files contain the information needed to present the users with a selection and then to take the selection and send a wakeup signal to the selected hardware address on the LAN. Here is the menu structure:
Number PC Name HW Address IP Address ====== =================== ================== ================ 1 ACCOUNTING 00:11:22:33:44:50 192.168.1.10 2 FINANCE 00:11:22:33:44:51 192.168.1.11 3 MANAGER 00:11:22:33:44:52 192.168.1.12
Here is the data file that corresponds with the menu:
1 00:11:22:33:44:50 192.168.1.255 2 00:11:22:33:44:51 192.168.1.255 3 00:11:22:33:44:52 192.168.1.255
Yes, I know we could grab the data direct from the menu using some tool other than ‘cut’. However, what is done here works even though it is not as elegant as some would like. If some of you with elite bash scripting skills would like to share how to do this with just the menu, please do so in a comment.
The one other item we need to address is waking up all the PC systems before the employees arrive in the morning on Monday through Friday each week. This is done in a cron job on the same Linux PC. Here is how the job might be set up:
30 6 * * 1-5 wakeonlan -i 192.168.1.255 -f /home/user/scripts/autowol.data
What this does is tell the cron scheduler to run the command “wakeonlan” at 6:30 AM (“30 6”) every Monday through Friday. (“1-5”) This command reads the hardware addresses from a file (“-f /home/user/scripts/autowol.data”) and then sends the wakeup signal to each address on the chosen subnet (“-i 192.168.1.255”). The hardware address data file looks like this:
00:11:22:33:44:50 00:11:22:33:44:51 00:11:22:33:44:52 00:11:22:33:44:53 00:11:22:33:44:54
It contains all the hardware addresses of the PC systems that need to be awakened at that time of day. One hardware address per line.
So, if you are an IT consultant, systems administrator or Joe User who wants to use Linux at home, perhaps this article gave you some idea of how to manage your own Remote Wakeup scenario.
|free hit counter|
Notice: All comments here are approved by a moderator before they will show up. Depending on the time of day this can take several hours. Please be patient and only post comments once. Thank you.