2013-08-19 32 views
0

上我試圖在遠程服務器上運行一個腳本,像這樣:SED不工作遠程機器

ssh [email protected] 'bash -c " 
     echo $SHELL; 
     cd /home/bldadmin/patch; 
     pwd; 
     echo '$int_ver_cnc'; 
     echo '$rev_ver_cnc'; 
     echo '$pre_ver_cnc'; 
     cp -Rf RP_'$pre_ver_cnc'-'$int_ver_cnc' RP_'$int_ver_cnc'-'$rev_ver_cnc'; 
     cd /home/bldadmin/patch/RP_'$int_ver_cnc'-'$rev_ver_cnc'/CSCONsap/data/twoway/manual; 
     rm rulePkg.zip; 
     mv cncrules-CNC60Test-1.48.0-1.49.0.zip rulePkg.zip; 
     cd /home/bldadmin/patch/RP_'$int_ver_cnc'-'$rev_ver_cnc'; 
     find . -name install.sh.orig; 
     sed -e 's/^\(patchid=\)\(.*\)/\1\"1.47.0-1.48.0\"/g' -e 's/^\(fromVersion=\)\(.*\)/\1\"1.47.0\"/g' -e 's/^\(toVersion=\)\(.*\)/\1\"1.48.0\"/g' install.sh.orig >newfile.sh.orig; 
"' 

這是我在我的本地機器上的腳本。它將SSH連接到遠程機器並執行一系列命令。所有命令正在執行,但sed不起作用。當本地執行工作正常,我不知道我缺少什麼,我提示以下錯誤:

"bash: -c: line 14: syntax error near unexpected token `(' bash: -c: 
line 14: `  sed -e s/^(patchid=)(.*)/11.47.0-1.48.0/g -e 
s/^(fromVersion=)(.*)/11.47.0/g -e s/^(toVersion=)(.*)/11.48.0/g 
install.sh.orig >newfile.sh.orig;' " 

sed命令?

+0

你引述的問題,'bash'認爲你終止雙在sed腳本的中間引用了文字。 – Thor

+0

我想你可能需要使用這裏的文件來轉義報價http://stackoverflow.com/questions/13934280/ssh-heredoc-bash-prompt – KeepCalmAndCarryOn

回答

3

非但沒有在報價頭痛保存腳本到一個文件script.sh (使用一個合理的描述性名稱)和運行的:

$ ssh [email protected] 'bash -s' < script.sh