我有一个bash脚本,在其中使用ssh
连接到另一台服务器并在那里运行一些命令。我发现一些网站上会出现错误信息(Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
),这是一个友好的提示,但我的bash脚本卡住了。这条消息出现后,没有其他命令被执行。其他论坛建议使用ssh -t
来抑制消息,但这对我不起作用。我的代码看起来像这样:
.
.
.
stty -echo
sshpass "pwd" ssh -o StrictHostKeyChecking=no usr@1.1.1.1 'su -lc "rm -rf tmp"' 2>/dev/null
stty echo
.
.
.
我使用
stty-echo
的原因是因为我需要切换用户到root,而密码会在终端上显示出来(这是我不想要的)。当我在连接服务器(ip: 1.1.1.1)上输入root密码后,我会收到错误信息 (Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.
)。
有什么建议吗?如果需要进一步解释,请告诉我。谢谢! (我的bash版本是GNU bash version 3.2.51(1))
编辑
当删除 2>/dev/null
时,我收到的错误消息是:
Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell.
stty: standard input: Invalid argument