2015-04-24 32 views
1

我使用以下shell腳本發送電子郵件。但電子郵件的主題總是顯示「This」而不是"This is L_1.R"'mutt'不顯示完整主題

program=("L_1" "L_2" "L_3" "L_4") 
    subject="The job is finished" 
    ssh -f c15-0330-01.ad.mtu.edu 'echo' "the job ${program[0]} is finished" '|' 'mutt "[email protected]" -s' "This is "${program[0]}".R"; 

回答

0

首先開始你想要的遠程命令的樣子,裸最低報價是什麼:

echo the job L_1 is finished | mutt [email protected] -s 'This is L_1.R' 

只有幾個需要引用讓他們從字面上傳遞到遠程shell的事情:管道字符和主題引號,以使這些空格不會將其分解爲與mutt分開的參數。

program=("L_1" "L_2" "L_3" "L_4") 
subject="The job is finished" 
ssh -f c15-0330-01.ad.mtu.edu echo the job ${program[0]} is finished '|' mutt [email protected] -s "'"This is ${program[0]}.R"'"; 

與較長命令,做同樣的事情:

cd $address && nohup Rscript ${program[0]}.R > ${program[0]}_sh.txt && echo the job ${program[0]} is finished | mutt [email protected] -s 'This is ${program[0]}.R' 

(僅與取代的變量)。

這裏,幾件事情需要被引用:

ssh -f c15-0330-01.ad.mtu.edu cd $address '&&' nohup Rscript ${program[0]}.R '>' ${program[0]}_sh.txt '&&' echo the job ${program[0]} is finished '|' mutt [email protected] -s "'"This is ${program[0]}.R"'" 
+0

你能幫我整理一下嗎'ssh -f c15- 0330-01.ad.mtu.edu'cd''$ address''&& nohup Rscript'「」$ {program [0]}「。R」'>'「」$ {program [0]}「_ sh.txt ''&&'echo'「作業$ {program [0]}已完成」'|' 'mutt「[email protected]」-s「這是''{{program [0]}'」。R「;'' –

+0

確定,試試。 – ysth

+0

'address =「/ home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10」' –

0

移動您的單引號。

ssh -f c15-0330-01.ad.mtu.edu 'echo' "the job ${program[0]} is finished" \ 
'|' 'mutt "[email protected]" -s "This is "'${program[0]}'".R";' 

編輯:我把變量出來的引號。主要的是空間被覆蓋。

+0

我試過,但它說'程序:未定義variable.'我不把雙引號單引號裏面的原因是,我不能在單引號之間定義變量。 –

+0

我在'echo'中放了'\ n',但它不起作用。 'ssh -f $ {host_list [0]} cd'''$ address''''&&'nohup Rscript $ {program [0]}。R'>'$ {program [0]} _ sh.txt'&&' echo $ job $ address $ {program [0]} \ n完成'|' mutt [email protected] -s「'」$ {host_list [0]} - Job $ {program [0]}。R完成了''「;' –