通过ssh运行一个程序失败,"错误打开终端:未知" [英] running a program through ssh fails with "Error opening terminal: unknown."
问题描述
当我尝试通过ssh执行一个简单的命令,那么它是成功的。例如。
When I try to execute a simple command through ssh, then it is successful. e.g.
#] ssh servername "echo abcd"
abcd
#]
然而,当我尝试使用以下命令,它将失败:
However, when I try the following command, it fails:
#] ssh servername ~/htopmem.sh
Error opening terminal: unknown.
#]
,其中htopmem.sh的内容如下。 (上 HTOP输出到人类可读的文件灵感来自马尔万Alsabbagh的答案)
where the content of htopmem.sh is below. (inspired by the answer of Marwan Alsabbagh on htop output to human readable file)
#!/bin/bash
echo q | htop | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | ~/aha --black --line-fix | grep Mem | grep -E -o "[0-9]+/[0-9]+"
如果我手动ssh到服务器并运行htopmem,则执行成功:
If I manually ssh to the server and run htopmem, then the execution is successful:
#] ./htopmem.sh
6515/24021
#]
如何使SSH服务器名〜/ htopmem.sh命令工作的任何想法?
any idea on how to make the "ssh servername ~/htopmem.sh" command work?
感谢您!
推荐答案
一个普通的 SSH
这样的命令没有一个的tty
(终端)。使用 -t
选项强制 SSH
来打开它的方式在终端。
A plain ssh
command like that does not have a tty
(terminal). Use the -t
option to force ssh
to open the terminal on its way in.
从手动:
-t
部队伪终端分配。这可用于在远程机器上执行任意的基于屏幕的方案,它可以是
非常有用的,例如,实施菜单服务时。多个 -t
选项强制tty分配,即使SSH有没有本地的tty。
Force pseudo-tty allocation. This can be used to execute arbitrary 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.
所以这会工作(好):
ssh -t servername ~/htopmem.sh
这篇关于通过ssh运行一个程序失败,"错误打开终端:未知"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!