[英]running a program through ssh fails with "Error opening terminal: unknown."
When I try to execute a simple command through ssh, then it is successful.当我尝试通过 ssh 执行一个简单的命令时,它是成功的。 eg
例如
#] ssh servername "echo abcd"
abcd
#]
However, when I try the following command, it fails:但是,当我尝试以下命令时,它失败了:
#] ssh servername ~/htopmem.sh
Error opening terminal: unknown.
#]
where the content of htopmem.sh is below. htopmem.sh 的内容如下。 (inspired by the answer of Marwan Alsabbagh on htop output to human readable file )
(灵感来自 Marwan Alsabbagh 关于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]+"
If I manually ssh to the server and run htopmem, then the execution is successful:如果我手动 ssh 到服务器并运行 htopmem,则执行成功:
#] ./htopmem.sh
6515/24021
#]
any idea on how to make the "ssh servername ~/htopmem.sh" command work?关于如何使“ssh servername ~/htopmem.sh”命令起作用的任何想法?
Thank you!谢谢!
A plain ssh
command like that does not have a tty
(terminal).像这样的普通
ssh
命令没有tty
(终端)。 Use the -t
option to force ssh
to open the terminal on its way in.使用
-t
选项强制ssh
在进入时打开终端。
-t
Force pseudo-tty allocation.
强制伪 tty 分配。 This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, eg, when implementing menu services.
这可用于在远程机器上执行任意基于屏幕的程序,这非常有用,例如在实现菜单服务时。 Multiple
-t
options force tty allocation, even if ssh has no local tty.多个
-t
选项强制分配 tty,即使 ssh 没有本地 tty。
So this would work (better):所以这会工作(更好):
ssh -t servername '~/htopmem.sh'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.