在远程节点上的ssh命令中使用SED [英] Using SED in a ssh command on a remote node

查看:42
本文介绍了在远程节点上的ssh命令中使用SED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wrote a script to ssh to some nodes and run a sed command inside the node. The script looks like

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 命令的开头.

It seems that the character ' is not treated as the begining of a sed command.

推荐答案

我建议替换

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'

如果您绝对要使用单引号:

If you absolutely want to use single quotes:

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

这篇关于在远程节点上的ssh命令中使用SED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆