projectz

Tech, Gadgets, Photography, Social Media and Poor Spelling

Linux Tip: Running Windows commands on remote servers not using SSH

linuxtip

I’ve had a requirement to produce a script which accessed about 4 windows PC servers (2003/2008 on a Domain from a bash script to obtain hard disk sizes from each machine, this can be done using SSH howeverthat involves getting SSH server installed on all the remote machines, not something we wanted to do at the time. This handy command unfortunatly is a bit buggy so not in the Ubuntu repos any more, however for the purpose I needed it performed very well.

Source: http://linuxwave.blogspot.co.uk/2010/03/running-windows-cmd-from-linux.html

To run windows cmd from linux box, there is one tool you could use, which is winexe. You can download the installer from here. There are 2 ways to install this tool:

1. Use the preinstalled version.
  • Download from here
  • Unpack the bz2 file: # bunzip2 winexe-static-081123.bz2
  • Change mod to allow execute: # chmod +x winexe-static-081123
  • Make soft link in your /usr/local/bin: # ln -s winexe-static-081123 /usr/local/bin/winexe
2. Compile from source
  • Install necessary packages (gcc, svn, *-devel….)
  • Get sources from here
  • Unpack the source file: # tar -xvjf winexe-source-081123.tar.bz2
  • Compile according to README file:
    • cd to unpacked tar.bz2 sources
    • ./autogen.sh
    • ./configure
    • make proto bin/winexe
  • Compiled file will be located in wmi/Samba/source/bin/winexe
  • Install winexe:
    install -s wmi/Samba/source/bin/winexe /usr/local/bin/winexe
To use it is very simple:
# winexe -U foo -W WORKGROUP -n FOO-PC //10.0.0.61 “cmd.exe”
where -U for username, -W for workgroup, -n for target machine netbios name, 10.0.0.61 is the ip address of the target machine and cmd.exe is to start windows command prompt.
Once connected, you will get command prompt like below:
Microsoft Windows [Version 5.2.3790]
(C) Copyright 1985-2003 Microsoft Corp.

C:\WINDOWS\system32>
To quit, just type exit at the windows command prompt.
That’s all 🙂
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: