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.
#]
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]+"
If I manually ssh to the server and run htopmem, then the execution is successful:
#] ./htopmem.sh
6515/24021
#]
any idea on how to make the "ssh servername ~/htopmem.sh" command work?
Thank you!
A plain
ssh
command like that does not have atty
(terminal). Use the-t
option to forcessh
to open the terminal on its way in.From the manual:
So this would work (better):