【问题标题】:cat in multiple ssh commands does not work多个 ssh 命令中的 cat 不起作用
【发布时间】:2016-06-11 15:03:54
【问题描述】:

这可能是非常基本的,但不幸的是我不知道如何用谷歌搜索它。

为什么下面的 sn-p 不能按预期工作?我的意思是,我怎样才能让cat 指向远程文件?

#!/bin/bash

ssh user@remoteaddress << EOF
  mkdir sandpit
  cd sandpit
  echo "foo" > foo.txt
  echo `cat foo.txt` > foo2.txt
EOF

【问题讨论】:

    标签: linux bash shell ssh heredoc


    【解决方案1】:

    将其用作:

    ssh -t -t user@remoteaddress<<'EOF'
    mkdir sandpit
    cd sandpit
    echo "foo" > foo.txt
    cat foo.txt > foo2.txt
    xargs kill < pid.txt
    exit
    EOF
    

    EOF 开头周围没有引号,所有单词都会受到 shell 扩展的影响,并且反向引号会在您当前的 shell 中扩展,而不是在 ssh 上。

    【讨论】:

    • 谢谢,这行得通。好吧,我真正想做的是kill `cat pid.txt`。这种情况我该怎么办?
    • 现在我检查了编辑,一切都解决了。非常感谢。
    猜你喜欢
    • 2017-03-26
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 2015-05-20
    • 2011-09-15
    • 2023-04-05
    相关资源
    最近更新 更多