目前我有一个bash脚本,在ssh上执行某些操作时会使用expect。它看起来像:
#!/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.
答案 0 :(得分:2)
因此,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.
答案 1 :(得分:-1)
这可以通过使用ssh
直接连接到框来解决(即不在脚本中)。
这样做,它会提示您更改密码。这样做,错误就会消失。
答案 2 :(得分:-1)
看起来您正在尝试运行ssh user@server passwd
,但由于密码已过期,您必须先更改密码。可能当你将expect作为spawn user@server
运行时,它会要求你输入密码,它会起作用。