首页 文章

放在后台时,ssh客户端(路由器上的dropbear)没有输出

提问于
浏览
4

我正在尝试使用Linux机器上的bash脚本在远程Linux机器上自动执行某些操作并且有一个工作命令(大括号是来自cmd连接的残余):

(ssh -i /path/to/private_key user@remoteHost 'sh -c "echo 1; echo 2; echo 3; uname -a"')

但是如果一个&符连接在后台执行它,它似乎执行,但是没有输出打印,既不在stdout上,也不在stderr上,甚至重定向到文件(在大括号内)都不起作用......:

(ssh -i /path/to/private_key user@remoteHost 'sh -c "echo 1; echo 2; echo 3; uname -a"') &

顺便说一句,我在Linux 2.4.37.10(在WRT54G上构建TomatoUSB)上运行BusyBox v1.17.4中的 ssh 客户端dropbear v0.52 .

Is there a way to get the output either? What's the reason for this behaviour?

编辑:

为方便起见,这是普通的 ssh 帮助输出(在我的TomatoUSB上):

Dropbear client v0.52
Usage: ssh [options] [user@]host[/port][,[user@]host/port],...] [command]
Options are:
-p <remoteport>
-l <username>
-t    Allocate a pty
-T    Don't allocate a pty
-N    Don't run a remote command
-f    Run in background after auth
-y    Always accept remote host key if unknown
-s    Request a subsystem (use for sftp)
-i <identityfile>   (multiple allowed)
-L <listenport:remotehost:remoteport> Local port forwarding
-g    Allow remote hosts to connect to forwarded ports
-R <listenport:remotehost:remoteport> Remote port forwarding
-W <receive_window_buffer> (default 12288, larger may be faster, max 1MB)
-K <keepalive>  (0 is never, default 0)
-I <idle_timeout>  (0 is never, default 0)
-B <endhost:endport> Netcat-alike forwarding
-J <proxy_program> Use program pipe rather than TCP connection

1天后修改:

无论是否有相同的结果,牙套都不会受伤 . 我想将ssh身份验证放到后台,因此 -f 选项不是解决方案 . 有趣的注意事项:如果指定了意外的选项(如 -v ),则会显示错误消息 WARNING: Ignoring unknown argument '-v' - 即使放在后台也是如此,因此从后台进程获取输出通常可以在我的环境中使用 .

我试过x86 Ubuntu常规的 ssh 客户端:它有效 . 我也在x86 Ubuntu上试过 dbclient :也可以 . 所以这个问题似乎特定于TomatoUSB构建 - 或者"dropbear v0.52"内部是一个未知的修复,在TomatoUSB和Ubuntu提供的构建之间(帮助输出的差异只是Ubuntu上的双倍大小的默认接收窗口缓冲区) . 一个过程如何知道它是否被置于后台? Is there a solution to the problem?

1 回答

  • 6

    我在OpenWRT路由器上遇到了类似的问题 . 如果没有stdin,则Dropbear SSH客户端不会写任何内容,例如当由cron运行时 . 我认为&对进程stdin具有相同的效果(无输入) .

    我在作者的bugtracker上找到了一些解决方法 . 尝试从/ dev / zero重定向输入 . 喜欢:

    ssh -i yourkey user@remotehost "echo 123" </dev/zero &
    

    当我试图在my blog page描述时,它对我有用 .

相关问题