ssh发送sed命令出现sed: -e expression #1, char 8: unterminated `s' command

最近在编写pipeline脚本,需要修改远端服务器的配置文件并重启,发送sed命令时出现上述错误

sh "ssh root@${nginx_ip} sed -i 's/server ${ip_port}/#server ${ip_port}/g' ${nginx_path}${PROJECT_NAME}.conf"

解决方法:将sed命令用单引号包住:

sh "ssh root@${nginx_ip} 'sed -i \"s/server ${ip_port}/#server ${ip_port}/\" ${nginx_path}${PROJECT_NAME}.conf'"

直接在控制台编写如下:

ssh [email protected] 'sed -i "s/server 192.168.2.118:10500/#server 192.168.2.118:10500/g" /usr/local/nginx/conf/conf.d/gray-deploy-server.conf'

你可能感兴趣的:(ssh发送sed命令出现sed: -e expression #1, char 8: unterminated `s' command)