gpt4 book ai didi

mysql - 在 Windows 上通过 putty 编写 ssh 脚本

转载 作者:可可西里 更新时间:2023-11-01 07:23:12 26 4
gpt4 key购买 nike

我需要编写从 Windows 机器恢复 Linux 机器的 mysql 脚本。我有 putty,我知道它具有 ssh 功能。这是我所拥有的:

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

我在编写脚本时遇到的问题是 putty 打开一个新窗口并将控制权转移到那里,所以之后会发生任何事情

putty.exe -ssh 

什么都不做。

最佳答案

您可以使用 -m 选项指定一个文件,其中包含要在远程连接上运行的命令。

例子:

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

C:\cmd.txt 的内容

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

来自Putty Documentation :

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

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

With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain `embedded' servers, such as Cisco routers.

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

关于mysql - 在 Windows 上通过 putty 编写 ssh 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12736683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com