Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I need to send a shell script/ or simple shell command from windows application (c#)
to linux server. Linux server will just execute it.


how can I do this?
can I do this using cygwin? or anything else.

please help me in asap.

Thanks in advance.
Posted
Updated 21-Jul-16 3:34am
Comments
Sergey Alexandrovich Kryukov 26-Nov-11 0:26am    
Did you even read what sygwin does?
--SA
mmdullah 26-Nov-11 0:44am    
I have seen it on web:

Originally Posted by theYinYeti
One way to do this:
- Install Cygwin, as well as the following handy "C:\cygwin\launch.bat" script:
Code:
@echo off
C:
chdir C:\_cygwin\bin
bash --login -i -c "%*"
- Run from your own .bat:
Code:
C:\cygwin\launch.bat ssh user@host "remotecommand"
Of course, you'll have to setup a passphrase-less key-based authentication to the host.

Yves.
Hi theYinYeti,

Thanks alot for your help and response. Can I know how do I do a passphrase-less key-based authentication? I'm new to this cygwin.

link: http://www.linuxquestions.org/questions/programming-9/how-to-execute-a-ssh-script-on-linux-server-from-windows-through-a-bat-script-581171/

The question makes me doubt that you have enough experience or basic understanding of technology to get to such problem, even though it is relatively simple.

You need to have Linux application which should play a role of network server, and Windows C# application — its client. A request would be sending a command. Now, it can be done on several different levels. One (very painless) way would be: create both client and server side in .NET where you can use sockets on the level of TcpClient/TcpListener, classical remoting or WCF. You can run a server-side application on Linux without recompilation using Mono:
http://en.wikipedia.org/wiki/Mono_%28software%29[^],
http://www.mono-project.com/[^].

Another variant based on Mono: install Apache and mod_mono (http://www.mono-project.com/[^], http://www.mono-project.com/Mod_mono[^]) and create an ASP.NET application with server side on Linux. In this case, even any Web browser can play the role of the client. Start here: http://www.asp.net/get-started[^]. A client can be also a regular C# Windows application using HttpWebRequest to work with a Web server on Linux, see:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx[^] (see the code sample).

There a are a number of other variants. For example, you can implement Web Service on Linux which would use soap:
http://en.wikipedia.org/wiki/Web_Service[^],
http://en.wikipedia.org/wiki/SOAP[^].

A lean solution can use raw sockets on both part and native programming on Linux part, presumably C++, but support of it (implementation of identical application-level protocol) could be more difficult that is both parts are CLR.

—SA
 
Share this answer
 
Comments
mmdullah 26-Nov-11 1:51am    
Thanks for your technical explanation. Yes, I am new to linux. but I need to do it quickly.

Meanwhile, I have explored ActiveSocket which is inline with your suggestion.
Would you please see that and do you think it will serve my purpose?
link: http://www.activexperts.com/network-component/howto/ssh/vcnet/
and user manual: http://www.activexperts.com/files/network-component/manual.htm#Ssh
Sergey Alexandrovich Kryukov 26-Nov-11 19:38pm    
ActiveSockets? I don't know, never tried as the libraries bound with .NET worked well enough for me so far; I don't like using any 3rd-party codes unless absolutely unavoidable. It can help you on .NET side, but I have no idea how about Linux.

If you are really new to Linux but have some experience with .NET, install Mono on Linux, it's reliable enough to run many .NET applications on Linux. In this way, you won't need to do double work: one for Linux, one for .NET and overcome many potential compatibility problems. Mono way will be the fastest in all cases, with ActiveSockets or not.

Good luck,
--SA
WinSCP[^] could help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900