Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating running command on Linux from Windows using PuTTY

I have a scenario where I need to run a linux shell command frequently (with different filenames) from windows. I am using PuTTY and WinSCP to do that (requires login name and password). The file is copied to a predefined folder in the linux machine through WinSCP and then the command is run from PuTTY. Is there a way by which I can automate this through a program. Ideally I would like to right click the file from windows and issue the command which would copy the file to remote machine and run the predefined command (in PuTTy) with the filename as argument.

like image 457
Nemo Avatar asked May 27 '11 02:05

Nemo


People also ask

Can we use Linux commands on PuTTY?

Putty facilitates a connection type range to select from Serial, SSH, Rlogin, Telnet, and Raw. Also, it ships along with various tools of the command-line for DSA and RSA key generator (also known as puttygen), SFTP (psftp), SCP (pscp), etc, which can be executed from the terminal.

How run Linux commands remotely Windows?

Syntax for running commands on a remote Linux or Unix hostssh : The ssh (or other SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. USER-NAME : Remote host user name. REMOTE-HOST : Remote host ip-address or host name, such as fbsd.cyberciti.biz.


2 Answers

Putty usually comes with the "plink" utility.
This is essentially the "ssh" command line command implemented as a windows .exe.
It pretty well documented in the putty manual under "Using the command line tool plink".

You just need to wrap a command like:

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

in a .bat script.

You can also use common shell constructs, like semicolons to execute multiple commands. e.g:

plink read@myhost ls -lrt /home/read/files;/etc/backups/do-backup.sh 
like image 143
James Anderson Avatar answered Sep 18 '22 19:09

James Anderson


There could be security issues with common methods for auto-login. One of the most easiest ways is documented below:

  • Running Putty from the Windows Command Line

And as for the part the executes the command In putty UI, Connection>SSH> there's a field for remote command.

4.17 The SSH panel

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

4.17.1 Executing a specific command on the server

In SSH, you don't have to run a general shell session on the server. Instead, you can choose to run a single specific command (such as a mail user agent, for example). If you want to do this, enter the command in the "Remote command" box. http://the.earth.li/~sgtatham/putty/0.53/htmldoc/Chapter4.html

in short, your answers might just as well be similar to the text below:

  • let Putty run command in remote server
like image 26
Gary Tsui Avatar answered Sep 19 '22 19:09

Gary Tsui