2015-04-24 33 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完成了''“;' –