Automate command launch on Linux from Windows using PuTTY

I have a scenario where I often need to run the linux shell command (with different file names) from windows. I use PuTTY and WinSCP for this (username and password are required). The file is copied to a predefined folder on the linux machine through WinSCP, and then the command is launched from PuTTY. Is there a way by which I can automate this with a program. Ideally, I would like to right-click the file from the windows and issue a command that would copy the file to the remote machine, and run a predefined command (in PuTTy) with the file name as an argument.

+52
linux windows putty automation
May 27 '11 at 2:24
source share
8 answers

When you log in automatically, you may experience security issues using common methods. Below is one of the easiest ways:

And for the part, the command is executed. In the putty user interface, Connection> SSH> there is a field for the remote command.

4.17 SSH Panel

The SSH panel allows you to configure settings that apply only to SSH sessions.

4.17.1 Executing a specific command on the server

In SSH, you do not need to start a general shell session on the server. Instead, you can have one specific command (for example, a mail user agent, for example). if you want to do this, enter the command in the "Remote command" field. http://the.earth.li/~sgtatham/putty/0.53/htmldoc/Chapter4.html

Your answers may look like the text below:

+22
May 27 '11 at 2:38
source share

Putty usually comes with the plink utility.
This is essentially the command line command "ssh" implemented as Windows.exe.
This is pretty well documented in the putty guide under "Using the Command Line Tool".

You just need to wrap a command like:

plink root@myserver /etc/backups/do-backup.sh 

in a .bat script.

+97
May 27 '11 at 2:38 a.m.
source share

You can write a TCL script and establish an SSH session on this Linux machine and automatically issue commands. Check out http://wiki.tcl.tk/11542 for a quick guide.

+3
May 27 '11 at 2:29
source share

You can create a putty session and automatically load the script on the server when the session starts:

 putty -load "sessionName" 

In the remote command, specify the remote script.

+2
May 08 '13 at 8:35
source share

You can perform both tasks (loading and executing a command) using WinSCP. Use a WinSCP script like:

 option batch abort option confirm off open your_session put %1% call script.sh exit 

Link for the call command:
https://winscp.net/eng/docs/scriptcommand_call

Link for syntax %1% :
https://winscp.net/eng/docs/scripting#syntax

Then you can run the script like:

 winscp.exe /console /script=script_path\upload.txt /parameter file_to_upload.dat 

In fact, you can put a shortcut in the above command in the Windows Explorer Explorer menu, then right-click on any file and go to "Send"> "Download" using WinSCP and execute the remote command (= name of the shortcut).

To do this, go to the %USERPROFILE%\SendTo folder and create a shortcut for the following purpose:

 winscp_path\winscp.exe /console /script=script_path\upload.txt /parameter %1 

See Create an entry in the Submit menu in Explorer .

+1
May 15, '13 at 10:48
source share

the code:

 using System; using System.Diagnostics; namespace playSound { class Program { public static void Main(string[] args) { Console.WriteLine(args[0]); Process amixerMediaProcess = new Process(); amixerMediaProcess.StartInfo.CreateNoWindow = false; amixerMediaProcess.StartInfo.UseShellExecute = false; amixerMediaProcess.StartInfo.ErrorDialog = false; amixerMediaProcess.StartInfo.RedirectStandardOutput = false; amixerMediaProcess.StartInfo.RedirectStandardInput = false; amixerMediaProcess.StartInfo.RedirectStandardError = false; amixerMediaProcess.EnableRaisingEvents = true; amixerMediaProcess.StartInfo.Arguments = string.Format("{0}","-ssh username@"+args[0]+" -pw password -m commands.txt"); amixerMediaProcess.StartInfo.FileName = "plink.exe"; amixerMediaProcess.Start(); Console.Write("Presskey to continue . . . "); Console.ReadKey(true); } } 

}

Example .txt command:

ps

Link: https://huseyincakir.wordpress.com/2015/08/27/send-commands-to-a-remote-device-over-puttyssh-putty-send-command-from-command-line/

+1
Aug 28 '15 at 12:44
source share

Try MtPutty , you can automate ssh login. This is a great tool, especially if you need to connect to multiple servers many times. Try here

Another tool worth trying is TeraTerm . It is very easy to use for ssh automation. You can get it here . But my favorite is always MtPutty.

0
Mar 30 '15 at
source share

Here is a complete solution.

  • Install AutoHotKey (ahk)
  • Match the script with the key (e.g. F9)
  • In ahk script, a) Ftp command file (.ksh) for Linux machine

    b) Use plink as shown below. Plink should be installed if you have putty.

session name plink -l username -pw password test.ksh

or

plink -ssh example.com -l username -pw password test.ksh

All steps will be performed sequentially when you press F9 in windows.

0
May 21 '15 at 12:06
source share



All Articles