通过 ssh 执行脚本时无法获得终端提示

通过 ssh 执行脚本时无法获得终端提示

我有以下脚本,在本地运行时工作正常

猫/tmp/input.sh

                echo -n ">> "
                read env
                exit;

当我运行时,我收到命令提示符,如下所示。

$/tmp/input.sh | echo "whatever"
$

到目前为止一切都很好。当我通过 ssh 运行此脚本时出现问题

ssh wladmin@myhost /tmp/input.sh | echo "whatever"

This system is for the use by authorized users only. All data contained
on all systems is owned by the company and may be monitored, intercepted,
recorded, read, copied, or captured in any manner and disclosed in any
manner, by authorized company personnel. Users (authorized or unauthorized)
have no explicit or implicit expectation of privacy. Unauthorized or improper
use of this system may result in administrative, disciplinary action, civil
and criminal penalties. Use of this system by any user, authorized or
unauthorized, constitutes express consent to this monitoring, interception,
recording, reading, copying, or capturing and disclosure.

IF YOU DO NOT CONSENT, LOG OFF NOW.

##################################################################
# *** This Server is using Centrify                          *** #
# *** Remember to use your Active Directory account          *** #
# ***    password when logging in                            *** #
##################################################################

正如您所看到的,我期望在命令提示符终端上进行控制,$但除非我按Crtl + C或其他,否则我不会得到命令提示符来进一步输入。

我尝试了ssh -T选项,但这没有帮助。

您能建议需要做什么吗?

答案1

正在echo "whatever"终止该echo -n ">> "行的脚本,因为它不接受来自脚本的任何输入 - 因此这种情况read env永远不会发生。我不明白为什么你会这样做,|echo但无论如何都会继续 - 当你执行 ssh 时,只有 input.sh 脚本会远程运行 - 并且它不“知道”到标准输出的文本将被拒绝。为了获得相同的效果,请远程运行所有内容,即引用或转义|

ssh wladmin@myhost /tmp/input.sh \| echo "whatever"

相关内容