通过 SSH 远程运行一次性交互式程序

spi*_*tor 1 remote-access ssh terminal curses

我有一系列生产服务器,我希望能够在这些服务器上运行某些实用程序,而无需通过 SSH 连接到机器。

不幸的是,其中一些程序(我到目前为止尝试过的 top 和 iotop)需要设置 Curses 和/或 TERM 环境变量,并且通过 SSH 从 shell 执行不起作用:

$ ssh myserver top
TERM environment variable not set.
$ ssh myserver iotop
Traceback (most recent call last):
  File "/usr/sbin/iotop", line 16, in <module>
    main()
  File "/usr/lib/python2.7/dist-packages/iotop/ui.py", line 571, in main
    main_loop()
  File "/usr/lib/python2.7/dist-packages/iotop/ui.py", line 561, in <lambda>
    main_loop = lambda: run_iotop(options)
  File "/usr/lib/python2.7/dist-packages/iotop/ui.py", line 465, in run_iotop
    return curses.wrapper(run_iotop_window, options)
  File "/usr/lib/python2.7/curses/wrapper.py", line 22, in wrapper
    stdscr = curses.initscr()
  File "/usr/lib/python2.7/curses/__init__.py", line 33, in initscr
    fd=_sys.__stdout__.fileno())
_curses.error: setupterm: could not find terminal
Run Code Online (Sandbox Code Playgroud)

有小费吗?这可能吗?

Den*_*ker 6

你说你想在没有 ssh 的情况下运行它们,但你通过 ssh 连接。这没什么意义:)

我假设您想在不启动 shell 的情况下通过 ssh 运行实用程序。这是可能的,即使它没有启动 shell,也只需让 ssh 为你分配一个 PTY:

ssh -t myserver top
Run Code Online (Sandbox Code Playgroud)