【问题标题】:sshpass with multiple commands BASH SCRIPT带有多个命令的 sshpass BASH SCRIPT
【发布时间】:2020-04-19 14:08:42
【问题描述】:

我想创建一个 bash 脚本,它显示从 mysql 返回的所有数据。 问题是,我需要插入多个命令,例如"mysql -u root" => "使用测试" => "SELECT * FROM test"

我已经通过创建 2 个文件对其进行了测试。只能创建第一个文件。以下是我测试过的版本。有人知道如何在行后输入所有命令吗? 感谢您的关注。

试试 1

sshpass -p "" ssh -o StrictHostKeyChecking=no root@xxx.xxx.xxx.xxx touch test/test1.txt & touch test2.txt

试试2

sshpass -p "" ssh -o StrictHostKeyChecking=no root@xxx.xxx.xxx.xxx touch test/test1.txt && touch test2.txt

试试3

sshpass -p "" ssh -o StrictHostKeyChecking=no root@xxx.xxx.xxx.xxx touch test/test1.txt; touch test2.txt;

试试4

sshpass -p "" ssh -o StrictHostKeyChecking=no root@xxx.xxx.xxx.xxx touch test/test1.txt || touch test2.txt

【问题讨论】:

    标签: mysql linux bash


    【解决方案1】:

    关于 sshpass,更好的方法是设置基于密钥的 ssh 身份验证,这样您就不需要输入密码

    http://www.linuxproblem.org/art_9.html

    关于运行多条命令,可以通过引用命令并用“;”分隔来实现,试试

    ssh user@server "echo \$HOSTNAME; echo \$SHELL"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 2017-11-22
      • 2013-09-14
      相关资源
      最近更新 更多