【问题标题】:Expect never matches the patternExpect 永远不会匹配模式
【发布时间】:2014-06-01 16:01:21
【问题描述】:

我正在尝试编写一个自动输入密码的脚本,但似乎期望与模式不匹配。

#!/usr/bin/expect --

set pass "test"
set timeout 5

spawn sudo ssh -i ~/.ssh/id_rsa StrictHostKeyChecking=no vongrad@localhost

expect {
  timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
  "*ssword*" {
    send "$pass\r"
  }
}

你有什么建议吗?

【问题讨论】:

  • 由于没有人对您的原始问题发表意见,您确定期望使用像“*”这样的外壳通配符。而不是真正的常规 experssions,这将作为 .*ssword.* 完成。试试看。祝你好运。

标签: linux bash ssh expect


【解决方案1】:

使用密钥(没有密码)而不是您在脚本中编写的密码登录怎么样?这样您就可以避免 ssh 提示您输入密码。 例如这里描述的:http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/

【讨论】:

  • 这只是我正在编写的代码的一部分,整个脚本将基于期望和发送。因此,我必须找到一种方法来做到这一点......
  • 但是为什么要使用密码登录呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
相关资源
最近更新 更多