Scripts through ssh through putty on windows

I need a mysql recovery script for a Linux machine from a Windows machine. I have putty, and I know that she has ssh capability. Here is what I have:

C:\Progra~1\Putty\putty.exe -ssh root@10.1.2.3 && mysql -u USER -pPASS db < /tmp/dump.sql 

My problem when writing a script is that the putty opens a new window and transfers control there, so everything that comes after

 putty.exe -ssh 

doing nothing.

+4
source share
1 answer

You can use the -m option to specify the file that contains the command to run on the remote connection.

Example:

 C:\Progra~1\Putty\putty.exe -ssh -m C:\cmd.txt root@10.1.2.3 

Content C:\cmd.txt

  mysql -u USER -pPASS db < /tmp/dump.sql 

From the Sleepers Documentation :

3.8.3.6 `-m ': read a remote command or script from a file

-m' option performs a similar function to the Remote Command' in the SSH panel of the PuTTY configuration window (see section 4.18.1). However, the `-m 'parameter expects to be given the name of a local file, and it will read the command from that file.

With some servers (in particular, Unix systems) you can even put several lines in this file and execute more than one command in a sequence or an entire shell script; but this is probably an abuse, and they cannot be expected to work on all servers. In particular, it is not known to work with certain β€œembedded” servers, such as Cisco routers.

This option is not available in the PSCP and PSFTP file transfer tools.

+7
source

Source: https://habr.com/ru/post/1437905/


All Articles