如何逃脱的SSH /远程bash命令的单引号字符? [英] How to escape the single quote character in a ssh / remote bash command?

查看:372
本文介绍了如何逃脱的SSH /远程bash命令的单引号字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个小套的脚本来远程启动,停止和检查过程的状态。在停止这些脚本应该寻找一个过程,并杀死它。所以我做的:

I'm building a small set of scripts for remotely starting, stopping and checking the status of a process. The stop of these scripts should look for a process and kill it. Therefore I do:

ssh deploy@hera 'kill -9 `ps -ef | grep MapReduceNode | grep -v "grep" | awk -F " " '{print $2}' | head -n 1`'

这里的问题是,awk的符号化一步都需要单引号和这些冲突与通过ssh执行远程命令使用单引号。如何可以将这些单引号进行转义?

The problem here is that the awk tokenization step needs single quotes and these clash with the single quote utilized for executing the remote command via ssh. How can these single quotes be escaped?

推荐答案

使用

ssh deploy@hera 'kill -9 `ps -ef | grep MapReduceNode | grep -v "grep" | awk -F " " '"'"'{print $2}'"'"' | head -n 1`'

这篇关于如何逃脱的SSH /远程bash命令的单引号字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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