のエスケープが正しく引用されたとエスケープになりますは、次のコマンドを引用し、sshコマンドライン
$ echo -e ssh -q rmthost 'bash -c "ps -ef|grep '\'''\\\<'defunct'\\\>''\''|grep -v grep|awk '\'''{print \$1}''\'' "'
ssh -q sbpsvrwm757 bash -c "ps -ef|grep '\<defunct\>'|grep -v grep|awk '{print $1}' "
のが、実行されると、結果が期待されているものではありません。
$ ssh -q rmthost 'bash -c "ps -ef|grep '\'''\\\<'defunct'\\\>''\''|grep -v grep|awk '\'''{print \$1}''\'' "'
root16986 16982 0 - ? 0:01 <defunct>
awkコマンドのdidn右の列を抽出するようだ。
は今、私はSiguzaによって提供されたリンクをたどっと思い付いた:
$ echo ssh -q rmthost "'"bash -c '"ps -ef|grep '"'\<defunct\>'|grep -v grep|awk '{print \$1}'"'"'"'"
ssh -q rmthost 'bash -c "ps -ef|grep '\<defunct\>'|grep -v grep|awk '{print $1}'"'
完璧すぎて脱出し、まだ動作しません見えること:
$ ssh -q rmthost "'"bash -c '"ps -ef|grep '"'\<defunct\>'|grep -v grep|awk '{print \$1}'"'"'"'"
Missing }
または、
$ echo ssh -q rmthost bash -c '"ps -ef|grep '"'\<defunct\>'|grep -v grep|awk '{print \$1}'"'"'
ssh -q rmthost bash -c "ps -ef|grep '\<defunct\>'|grep -v grep|awk '{print $1}'"
$ ssh -q rmthost bash -c '"ps -ef|grep '"'\<defunct\>'|grep -v grep|awk '{print \$1}'"'"'
root 16986 16982 0 - ? 0:01 <defunct>
または
$ echo ssh -q rmthost "bash -c \"ps -ef |grep '\<defunct\>'|grep -v grep| awk '{print \$1}'\""
ssh -q rmthost bash -c "ps -ef |grep '\<defunct\>'|grep -v grep| awk '{print $1}'"
$ ssh -q rmthost "bash -c \"ps -ef |grep '\<defunct\>'|grep -v grep| awk '{print \$1}'\""
root 16986 16982 0 - ? 0:01 <defunct>
理由は何ですか?
> /var/tmp/1.ouy 2> & 1のように、bashスタイルの出力リダイレクトを有効にするにはbash -cが必要です。
あなたのご協力をお待ちしております。
ありがとうございました。私はそのルールに従っていますが、それでも動作させることはできません。上記の更新を参照してください – AlexL
'ssh rmthost" ps -ef | grep \ "\ \" | grep -v grep | awk '{print \ $ 1}' "'に何が間違っていますか? sshに引数を二重引用符で囲むことで、すべての厄介なことを避けることができます。 –
また、 'bash -c'はここでは冗長です。 sshはコマンド文字列をシェル自体に送り、エスケープするレベル全体を保存します。 –