【问题标题】:expect script change password prompted over ssh期望通过 ssh 提示脚本更改密码
【发布时间】:2013-08-25 20:41:16
【问题描述】:

目前我有一个 bash 脚本,它在通过 ssh 做一些事情时在其中使用了期望。它看起来像:

#!/bin/bash
#some bash stuff here
...
/usr/bin/expect -c '
    spawn somescript.sh
    expect "password:"
    send "$PASSWD"
'
...

somescript.sh 通过 ssh 对远程服务器执行命令,但现在我的登录需要更改密码。我试过了

/usr/bin/expect -c '
    spawn somescript.sh
    expect "password:"
    send "$PASSWD"
    expect "current password"
    send "$PASSWD"
    expect "new password"
    send "$NEWPASSWD"
'

但我收到一条错误消息:

WARNING: Your password has expired.\n Password change required but 
no TTY available.

【问题讨论】:

    标签: bash ssh expect


    【解决方案1】:

    所以,somescript.sh 建立了一个ssh 连接,然后您会收到有关 TTY 不可用的错误消息。

    试试-t 选项!

    来自ssh man page

    -t   Force pseudo-tty allocation.  This can be used to execute arbi-
         trary screen-based programs on a remote machine, which can be
         very useful, e.g., when implementing menu services.  Multiple -t
         options force tty allocation, even if ssh has no local tty.
    

    【讨论】:

      【解决方案2】:

      这可以通过使用ssh 直接连接到盒子来解决(即不在脚本中)。

      这样做,它会提示您更改密码。这样做,错误就会消失。

      【讨论】:

      • 这个线程是关于使用期望实现自动化的。你的回答没有帮助。 -1
      • @JasonLeMonier - 问题是关于为什么期望失败,听起来他认为这可能与期望有关 - 它不是......这是因为他的密码需要更改,而且很容易解决该问题的方法是使用 ssh 正常连接。
      【解决方案3】:

      您似乎正在尝试运行ssh user@server passwd,但由于您的密码已过期,您必须先更改它。可能当您以 spawn user@server 运行 expect 时,它会要求您更改密码并且它会起作用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-21
        • 1970-01-01
        • 2011-10-25
        • 2015-03-06
        • 2012-01-04
        • 1970-01-01
        • 2017-06-11
        • 2014-10-14
        相关资源
        最近更新 更多