使用 SSH 时转义引号
我正在尝试为我的 PHP 应用程序构建一个简单的部署脚本。我知道有几种工具可以完成这项工作(Capistrano、Phing 等),但对于我的简单部署例程来说,它们似乎需要大量工作。
我使用 sshpass 来避免一遍又一遍地输入密码。但上传压缩安装程序后,我需要 ssh 进入服务器并运行一些命令。其中之一是 sed。所以,引号破坏了我的脚本。它是这样的:
sshpass -p foo ssh user@host " cd /www/htdocs/foo/bar echo 'Untar and remove installer' tar -zxf install.tar.gz sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');" index.php > tmp && mv tmp index.php sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');/" admin/index.php > tmp && mv tmp admin/index.php "
正如您所看到的,我使用双引号来开始我的 SSH 语句,但我也需要在 sed 上使用它们。
任何建议将不胜感激。谢谢!
I'm trying to build a simple deployment script for my PHP apps. I know there are several tools for this job (Capistrano, Phing, etc.) but they seem like a lot of work for my simple deployment routine.
I use sshpass to avoid typing my password over and over again. But after uploading my compressed installer, I need to ssh into the server and run some commands. One of which is sed. So, quotes are breaking my script. It's something like this:
sshpass -p foo ssh user@host " cd /www/htdocs/foo/bar echo 'Untar and remove installer' tar -zxf install.tar.gz sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');" index.php > tmp && mv tmp index.php sed "s/define('ENVIRONMENT', 'development');/define('ENVIRONMENT', 'production');/" admin/index.php > tmp && mv tmp admin/index.php "
As you can see, I use double-quotes to start my SSH statements, but I also need to use them on sed.
Any suggestions would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
转义内部引号是正常的方法。这不行吗?
Escaping the internal quote marks is the normal way. Does this not work?
可以使用此处文档代替吗?:
Can a here-document be used instead?: