#! /bin/env bash # remote shutdown of windows machine # Author: R. W. Rodolico # # Copyright: 20151021 Daily Data, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # see http://lifehacker.com/5275652/shut-down-your-windows-pc-remotely-from-linux # Requires samba. Under Debian # apt-get install samba-common # see notes at bottom about how to set up the Windows machine # modify the following for your installation # ip of windows machine IPADDRESS=ip.of.windows.server # this user must have remote shutdown permission, generally a member of the Adminmistrators group USERNAME=username_of_admin_on_server # the password for that user. This is a serious breach of security, so think safe PASSWORD=password_of_USERNAME # this must be the name as seen by your DOM0 of the Windows machine as seen from xl list command DOMU_NAME=my-windows-server # checks to see if virtual still running using xl list and parsing it for $DOMU_NAME check_shutdown () { xl list | grep $DOMU_NAME > /dev/null || return 1 return 0 } echo "Shutting Down $DOMU_NAME" # if the domain not running, simply exit if check_shutdown then # send halt command to virtual net rpc shutdown -f -I $IPADDRESS -U $USERNAME%$PASSWORD # Check every 5 seconds to see if it has gone away while check_shutdown do echo -n '. ' sleep 5 done fi echo echo "$DOMU_NAME Shut down" # For Windows 7, it doesn't work because remote shutdown is disabled on it. You will need to # http://ubuntuforums.org/showthread.php?t=173440&page=7 # http://www.howtogeek.com/howto/windows-vista/enable-mapping-to-hostnamec-share-on-windows-vista/ # A. shut down the firewall # B. Add # HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System # LocalAccountTokenFilterPolicy DWORD 0x00000001 (1)