Shutdown a Windows machine from the UNIX command line

Picked up this nifty trick from command-line-fu

$ net rpc shutdown -I ipAddressOfWindowsPC -U username%password

This will issue a shutdown command to the Windows machine. username must be an administrator on the Windows machine. Requires samba-common package installed. Other relevant commands are:

net rpc shutdown -r : reboot the Windows machine

net rpc abortshutdown : abort shutdown of the Windows machine


net rpc

to show all relevant commands

The “net rpc service” command looks spiffy.

(michael)> net rpc

net rpc info             show basic info about a domain
net rpc join             to join a domain
net rpc oldjoin             to join a domain created in server manager
net rpc testjoin         tests that a join is valid
net rpc user             to add, delete and list users
net rpc password <username> [<password>] -Uadmin_username%admin_pass
net rpc group         to list groups
net rpc share         to add, delete, list and migrate shares
net rpc printer         to list and migrate printers
net rpc file             to list open files
net rpc changetrustpw     to change the trust account password
net rpc getsid         fetch the domain sid into the local secrets.tdb
net rpc vampire         syncronise an NT PDC’s users and groups into the local passdb
net rpc samdump         diplay an NT PDC’s users, groups and other data
net rpc trustdom         to create trusting domain’s account or establish trust
net rpc abortshutdown     to abort the shutdown of a remote server
net rpc shutdown         to shutdown a remote server
net rpc rights        to manage privileges assigned to SIDs
net rpc registry        to manage registry hives
net rpc service        to start, stop and query services
net rpc audit            to modify global auditing settings
net rpc shell            to open an interactive shell for remote server/account management

‘net rpc shutdown’ also accepts the following miscellaneous options:
-r or –reboot    request remote server reboot on shutdown
-f or –force    request the remote server force its shutdown
-t or –timeout=<timeout>    number of seconds before shutdown
-C or –comment=<message>    text message to display on impending shutdown

Accessing Windows shares from the Solaris/Linux command line

Periodically I need to access a Windows share from a Solaris or Linux box. If Samba is installed on the system, this is easy to do with the smbclient utility. To access the Windows server named “milton” from the command line, you can run smbclient with the “-U” option, the name of the user to authenticate with, and the name of the server and share to access:

$ smbclient -U “domain\matty” //milton/foo

In this example, I am authenticating as the user matty in the domain “domain,” and accessing the share foo on the server milton. If smbclient is unable to resolve the server, you will need to make sure that you have defined a WINS server, or the server exists in the lmhosts file. To define a WINS server, you can add a line similar to the following (you can get the WINS server by looking at ipconfig /all on a Windows desktop, or by reviewing the LAN traffic with ethereal) to the smb.conf file:

wins server =

If you don’t want to use WINS to resolve names, you can add an entry similar to the following to the lmhosts file: milton

Once you are connected to the server, you will be greeted with a “smb: \>” prompt. This prompt allows you to feed commands to the server, such as “pwd,” “dir,” “mget,” and “prompt.” To retrieve all of the files in the directory foo1, I can “cd” into the foo1 directory, use “prompt” to disable interactive prompts, and then run “mget” to retrieve all files in that directory:

smb: \> pwd
Current directory is \\server1\foo

smb: \> dir

received 10 entries (eos=1)
  .                                  DA        0  Mon May 22 07:19:21 2006
  ..                                 DA        0  Mon May 22 07:19:21 2006
  foo1                               DA        0  Sun Dec 11 04:51:12 2005
  foo2                               DA        0  Thu Nov  9 09:48:40 2006
         < ..... >

smb: \> cd foo1

smb: \foo1\> prompt
prompting is now off

smb: \foo1\> mget *

received 38 entries (eos=1)
getting file \foo1\yikes.tar of size 281768 as yikes.tar 411.3 kb/s) (average 411.3 kb/s)
    < ..... >

smb: \foo1\> exit

The smbclient manual page documents all of the available commands, and provides a great introduction to this super useful utility. If you bump into any issues connecting to a remote Windows server, you can add “-d” and a debug level (I like debug level 3) to the smbclient command line. This is perfect for debugging connectivity issues.