How do I run a script in linux from a windows service?

Does anyone know an elegant way to initiate a bash script (to run on a Linux box) from a Windows service written in C #?

I can only think of some putty combination that does auto login and automatically runs the command on login. But that seems awkward and a little insecure.

The security does not have to be very high since both windows are inside the internal LAN inside the corporate firewall. And only system administrators can enter the window window.

+2


source to share


5 answers


You can use SSH with key authentication to run a command without entering or saving a password in the application. You must enable authentication on the Linux SSH server (follow the instructions here to create and store the key in the appropriate location on the server) and then you can run

plink -i <key_location> user@machine "command"

      

in the application via Process.Start ()



plink is a command line utility that comes with PuTTY.

EDIT: If you don't want PKI (this might not be a good idea, but you know your environment), you can set up an rsh server in linux box and send the command via rsh ( Cygwin rsh might work better with linux boxes)

+2


source


If they are behind a firewall, you can create a mini-server on a linux machine that listens for commands on a given port. Windows can connect to this port and send a command.



+1


source


If samba is running in linux box you can use magic script http://oreilly.com/catalog/samba/chapter/book/ch08_02.html

I would probably start a web server on a linux box and run the script via an http request

0


source


I do this with Cygwin , including additional packages for ssh and cron. Almost as elegant as using a real Unix machine.

0


source


Since you asked for something easy to use from C #, the webserver method might be the best: fast and easy, and no password needed. Set up a Linux script in / var / www / cgi-bin and run it with C # magic to open an http socket and call http: // hostname / cgi-bin / programname .

0


source







All Articles