【问题标题】:find remote hostname with ssh command使用 ssh 命令查找远程主机名
【发布时间】:2020-02-10 08:31:21
【问题描述】:

我正在尝试通过 ssh 命令查找远程服务器的远程主机名和磁盘卷。

ssh user@remotehost echo $(df -B1G $vol|awk 'NR==2{printf "%s %dGB/%dGB\n",$5,$3,$2}') $(hostname) $vol

磁盘的输出如预期的那样,但是命令中的主机名和卷给出了本地主机和卷的输出。我得到的输出是:

diskusgae% usedGB/totalGB localhost volume_on_localhost

谁能指导我如何获得所需的输出?

diskusgae% usedGB/totalGB remotehost volume_on_remotehost

【问题讨论】:

  • 引用您的命令,例如 "command1 && commands2""command1; command2"

标签: linux bash shell ssh


【解决方案1】:

我建议使用这种语法以避免 '\" 混乱

ssh -q $host bash <<- \EOF
    vol=/dev/mapper/vg1-home
    df -B1G $vol | awk 'NR==2{printf "%s %dGB/%dGB",$5,$3,$2}'
    printf " $HOSTNAME $vol"
EOF

或者在sh的情况下这样

ssh -q $host sh <<- \EOF
    vol=/dev/mapper/vg1-home
    df -B1G $vol | awk 'NR==2{printf "%s %dGB/%dGB",$5,$3,$2}'
    printf " %s $vol" $(hostname)
EOF

【讨论】:

  • 谢谢伊万,我实际上需要一行输出。
猜你喜欢
  • 2015-07-05
  • 2020-11-07
  • 2018-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-01
  • 2021-05-29
  • 1970-01-01
相关资源
最近更新 更多