【问题标题】:Using SED in a ssh command on a remote node在远程节点上的 ssh 命令中使用 SED
【发布时间】:2017-04-03 10:01:57
【问题描述】:

我编写了一个脚本来 ssh 到一些节点并在节点内运行 sed 命令。脚本看起来像

NODES="compute-0-3"
for i in $NODES 
do
  echo $i
  ssh $i 'sed -i \'s/172.16.48.70/172.20.54.10/g\' /etc/hosts;'
done

但是,错误是

unexpected EOF while looking for matching `''
syntax error: unexpected end of file

似乎' 字符不被视为sed 命令的开头。

【问题讨论】:

    标签: bash ssh sed


    【解决方案1】:

    我建议更换

    ssh $i 'sed -i \'s/172.16.48.70/172.20.54.10/g\' /etc/hosts;'
    

    通过

    ssh "$i" 'sed -i "s/172.16.48.70/172.20.54.10/g" /etc/hosts'
    

    如果你绝对想使用单引号:

    ssh "$i" 'sed -i '"'"'s/172.16.48.70/172.20.54.10/g'"'"' /etc/hosts'
    

    【讨论】:

    猜你喜欢
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 2020-05-25
    • 2021-05-11
    • 2022-06-06
    相关资源
    最近更新 更多