views:

1577

answers:

4

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?

+5  A: 

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 script-on-aix-box.sh".

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.

Tanktalus
Thanks for the answer. Two related questions: (1) Why is it better to use cygwin's ssh utility instead of the Windows ssh utility? (2) What are the keys for? Does that allow cross-platform authentication, or is it just a way of asymmetrically encrypting the password?
John M Gant
Actually, I don't think it's built in to Windows (bad assumption on my part). I think it's a third-party utility we have installed. If I run into problems with the ssh I have I'll try cygwin. Thanks again.
John M Gant
+3  A: 

ssh [email protected] "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.

jsight
+1  A: 

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

Jason Baker
+1  A: 

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.

--edit--

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)

Tracker1
I like the AIX service suggestion, too.
Tanktalus