目前我有一个bash脚本,在ssh上做一些事情时使用expect.看起来像:
#!/bin/bash
#some bash stuff here
...
/usr/bin/expect -c '
spawn somescript.sh
expect "password:"
send "$PASSWD"
'
...
Run Code Online (Sandbox Code Playgroud)
somescript.sh通过ssh对远程服务器执行命令,但现在我的登录需要更改密码.我试过了
/usr/bin/expect -c '
spawn somescript.sh
expect "password:"
send "$PASSWD"
expect "current password"
send "$PASSWD"
expect "new password"
send "$NEWPASSWD"
'
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误说:
WARNING: Your password has expired.\n Password change required but
no TTY available.
Run Code Online (Sandbox Code Playgroud)
因此,somescript.sh建立ssh连接后您会收到有关 TTY 不可用的错误。
尝试-t选项!
从ssh 手册页:
-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.
Run Code Online (Sandbox Code Playgroud)