【发布时间】:2018-01-16 15:23:26
【问题描述】:
我需要通过管道传输多个 ssh 命令才能在远程机器上运行命令。 这些命令在单个 ssh 上运行良好,但在管道 ssh 之后却不行。 例如
ssh abc@remotemachine1.com "a=hello ; echo \$a"
回你好 但是
ssh abc@remotemachine1.com ssh abc@remotemachine2.com"a=hello ; echo \$a"
不产生任何输出。
同样:
ssh abc@remotemachine1.com "mountedDir=\$(df \tmp | grep -vi filesystem | rev | cut -d ' ' -f 1); mount | grep -w \$mountedDir"
工作正常,产生以下输出:
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,noquota)
但是
ssh abc@remotemachine1.com ssh abc@remotemachine2.com "mountedDir=\$(df \tmp | grep -vi filesystem | rev | cut -d ' ' -f 1); mount | grep -w \$mountedDir"
抛出以下错误:
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
注意:从我的机器到 remotemachine1.com 和从 remotemachine1.com 到 remotemachine2.com 建立无密码 ssh
【问题讨论】:
标签: linux ssh centos redhat cut