Archives

You are currently viewing archive for August 2010

Shutting down Windows from Linux

I had to do some research on how to remotely shut down a Windows computer from a Linux host and decided to share :-)

My test environment:


  • Gentoo linux running on my laptop
  • Windows XP SP3 running in a VirtualBox guest


The command (you need Samba installed on your Linux machine):

net rpc shutdown -t 10 -f -C "Remote shutdown initiated" -I 192.168.56.2 -U Erik

Broken down, that becomes:


  • -t 10 to give users 10 seconds to hit Ctrl-S
  • -f to force applications to quit without asking the user to save (so they can't get in the way of the shutdown)
  • -C "Remote shutdown initiated" is the message that should be displayed to any logged-in users
  • -I 192.168.56.2 the IP address at which the machine to shut down is located. In my case, the host-only network adapter
  • -U Erik is my username on the Windows machine. Works also as \ (don't forget to escape the backslash if your shell requires it!) or as \
  • If you like, you can add -r to reboot the machine instead of shutting it down.


If you don't want to be asked for your password, append it to your username with a % sign, like so: -U %

Of course, with Windows being involved, this doesn't work right out of the box ;-) In my case, after being asked for the password the net rpc command reported "Shutdown of remote machine succeeded". The Windows XP machine didn't shut down. It didn't even show me a message. A little Wireshark magic ended up revealing the error code "WERR_ACCESS_DENIED" being sent across the wire. (note to self: maybe a newer version of samba will actually do something with this error?)

Long story short: the solution is to have file sharing enabled, but to disable simple file sharing. To do so, open Explorer, go to Tools -> Folder options -> View (yes, it's the most logical place to put this ) and uncheck "Use simple file sharing" (all the way at the bottom of the list).

Error: Could not stat() command file '/var/lib/nagios3/rw/nagios.cmd'!

I ran into this error while messing around with nagios. Manually playing around with on /var/lib/nagios3/rw/nagios.cmd and its containing directories didn't seem to help much, so I went a-googlin'.

Here is the solution.

In short: (in case that blog goes down and I need it again ;-) ) :

sudo /etc/init.d/nagios3 stop
sudo dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
sudo dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
sudo /etc/init.d/nagios3 start