How to execute a Unix shell script from Windows

I’ve got an AIX script I would like to run from a .NET application. I’m not opposed to kicking off a Windows batch file if that gives me better options.

Most of what I’ve seen on Google relates to using a tool such as rsh or Plink, or using ssh or telnet. I don’t have access to rsh or Plink (although I do have PuTTY and could probably get Plink). I can ssh to the AIX box but telnet is disabled.

I’ll need a way of passing the user’s credentials.

Can anyone recommend the best way to call a Unix script from a Windows application?

Best Answer:

Install cygwin. Include the ssh function. Set up your ssh keys – private key on windows, public key on the AIX box. Then you can run “ssh user@aixbox”.

Best to have the script on AIX, though you can use scp to copy the file to AIX first. Passing a long command line through ssh is error prone – not due to it being ssh, but because getting escapes properly set up to pass from .NET through ssh to ksh or whatever is running on AIX is just painful. Best to keep things as simple as possible, preferably just a single command which can then be a script that does multiple things.

To answer your comments, which would take too long for another comment:

(1) Why is it better to use cygwin’s ssh utility instead of the Windows ssh utility?

a) I know it better, so I wouldn’t know to suggest any windows ssh utility (I didn’t even know Windows came with an ssh utility), and b) cygwin’s ssh utility stands a better chance of being standard ssh with all the familiarity us unix freaks love. 🙂

(2) What are the keys for? Does that allow cross-platform authentication, or is it just a way of asymmetrically encrypting the password?

The keys allow passwordless access. If you set up your private key as passwordless (not usually recommended, but if you can keep your machine secure, it works well for automated tools), your tool will be able to just ssh over with no password prompts – this makes things much easier.

Other Answer 1:

ssh eximadmin@ “cat somefile.log”

(where cat somefile.log is replaced with the command that you want to run)

I think the easiest way to do it would be to call your ssh program (whether that be ssh, plink, or something else) from a batch file that is called from your .net app.

Other Answer 2:

I second the cygwin suggestion, but one other option that you have is Microsoft’s Services for UNIX.

Other Answer 3:

What I would do, would be to setup a service (https) interface on the AIX box that the .Net application can run. This is really a matter of how you want to expose your script on the AIX box. IMHO Java + Tomcat would be easy enough to get setup on the AIX box, just make sure you limit your exposure, and/or require an authentication ticket for the AIX service. This isn’t so much a .Net question as an architectural decision.


As others have suggested, you can use Cygwin as well. There are SSH components for .Net you can use as well, which may be more transparent for you. (Commercial and FOSS)