【问题标题】:Run local Perl script on remote server through expect通过 expect 在远程服务器上运行本地 Perl 脚本
【发布时间】:2013-08-30 17:37:06
【问题描述】:

我的本​​地机器上有一个 Perl 脚本,我想在远程服务器上运行它。以下命令可以正常工作:

ssh user@ipaddress "perl - --arg1 arg1 --arg2 arg2" < /path/to/local/script.pl

问题是出现了一个提示要求我输入密码的提示,而我不想那样做。

我在网上看了一圈,找到了3个解决方案:

  • 使用公钥/私钥身份验证 -> 在我的情况下不行
  • 使用 sshpass -> 不在我公司的“官方”仓库中,因此无法安装
  • 使用期望

我按照此页面创建了我的期望脚本(我是新来的):How to use bash/expect to check if an SSH login works,我从正确答案中获取了脚本,并将前 3 行替换为 #!/usr/bin/expect -f 以获得期望脚本。

然后我跑了

./ssh.exp user password ipaddress "perl - --arg1 arg1 --arg2 arg2" < /path/to/local/script.pl

我有一个超时错误。就好像我跑了./ssh.exp user password ipaddress "perl"

我也试过把引号像

./ssh.exp user password ipaddress '"perl - --arg1 arg1 --arg2 arg2" < /path/to/local/script.pl'

但我有一个/path/to/local/script.pl not found 错误。

那么谁能帮我弄清楚如何通过 expect 运行脚本?非常感谢。

【问题讨论】:

    标签: expect


    【解决方案1】:

    好的,我自己找到了。

    仍在使用此答案How to use bash/expect to check if an SSH login works,但我将第 6 行替换为

    set pid [ spawn -noecho sh -c "ssh $1@$3 $4 < /path/to/local/script.pl" ]
    

    一切都像魅力一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 2018-07-18
      • 2013-12-28
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 2021-06-15
      相关资源
      最近更新 更多