我已将自己的应用程序设置为远程主机上用户的 shell。我的应用程序从 stdin 读取数据并将输出打印到 stdout。
如果我这样做并输入多行文本,应用程序将按预期工作。ssh [email protected]
但是,如果我这样做:
ssh [email protected] < file.txt
然后我的工具只处理第一行,然后退出。
有什么线索吗?
答案1
我会怀疑您的应用程序。它是否尝试写入STDERR
但失败了?它记录了什么吗?它如何缓冲输入?(如果答案是“根本没有”,则其余输入会在应用程序未监听时到达)。“远程主机”是什么系统?
这对我有用:
walt@bat:~(0)$ seq 1 4 >14.txt; ssh localhost <14.txt
Pseudo-terminal will not be allocated because stdin is not a terminal.
walt@localhost's password:
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-58-generic x86_64)
-bash: line 1: 1: command not found
-bash: line 2: 2: command not found
-bash: line 3: 3: command not found
-bash: line 4: 4: command not found
也许您可以使用expect
,或者它的变体之一:
walt@bat:~(127)$ apt-cache search expect | grep -w expect
empty-expect - Run processes and applications under pseudo-terminal
expect - Automates interactive applications
expect-lite - quick and easy command line automation tool
libjs-expect.js - behavior driven test assertions - JavaScript library
libnet-scp-expect-perl - Wrapper for scp to send passwords via Expect
libtest-expect-perl - module for automated driving and testing of terminal-based programs
node-expect.js - behavior driven test assertions - Node.js module
tcl-expect - Automates interactive applications (Tcl package)
tcl-expect-dev - Automates interactive applications (development)