In these days of conscientious power saving and escalating electricity bills (thank-you Aurora) I have compromised with my home media server by having it turned off when not in use. But I have contrived a cunning way of remotely powering it up when needed, from any system in the house. The following instructions can in fact be used to shut down any 'nix box which is running the ssh daemon.
Turning it on
Remote powering on of a system uses the rather useful Wake-On-LAN (WoL) technology which is natively supported by FreeBSD. On shutdown the system's network interface remains active and listens for a specific packet of data to power the rest of the system on again. For more background on WoL check out the following:
Using the command line wolcmd.exe I have written a batch file to wake up the server from a Windows workstation. It also maps a drive and opens Windows Explorer to start viewing files..
@echo off
wolcmd 0105236b3d09 192.168.0.1 255.255.255.0
wait 30
ping 192.168.0.1
net use m: \\myserver\music
explorer /n,/e,M:
exit
I even got a bit fancy and added a pretty icon to the batch file shortcut on my desktop. With the Unix server running I can now get on with the busines of enjoying my lovely music.
Turning it off again
And so we reach the point of this article. I had been using the legendary PuTTY to SSH into the Unix box and run the shutdown command but this was a bit cumbersome, requiring a login, an su to root and then typing the command. How much nicer to be able to click another icon..
Enter Plink (PuTTY Link) which allows you to do PuTTY-like things from the command line. The astute reader will already see where this is heading..
I will also need to use the sudo command to run the shutdown on the server. No probs on Linux but FreeBSD doesn't come with sudo as a native application. However it can be installed by referring to the rather excellent companion article Using sudo on FreeBSD.
Back to Plink. Once again a batch file is used to automate what would be typed at the command line. So for instance a simple ssh login from the CMD prompt would look like this:
plink -ssh andym@myserver -pw mypassword
Make sure that the plink.exe file is in the system path so it's accessible from anywhere. Easiest way is to copy it to the C:\Windows\system32 directory. Then open a command prompt (Start|Run|cmd) and manually type a test login. Note from the above example that the Plink executable takes command line options, such as -ssh for protocol and -pw for password.
Plink can also take instructions from an external text file using the -m switch. This will tell Plink what commands to run once it has made a successful ssh connection. Here is an example of invoking the external file - note the full path to the text file is required. To automate the login process, this single line is all that is required in the batch file..
plink -ssh andym@myserver -pw mypassword -m f:\progs\plink1.txt
Finally add the command(s) to be run after login, to the external text file. I just need to tell it to shut the system down, so that's literally all I have in my plink1.txt file..
Note the need for sudo. Your basic plebeian user is not allowed to shut the system down. The Using sudo on FreeBSD article contains an example of how to grant normal users the shut the system down privilege.
As for Plink, it really is the dog's bollocks for task automation potential. For the full lowdown on the power of Plink, go to its creator Simon Tatham's page.
Now I have TWO pretty useful icons on my desktop.. 
- A.