【问题标题】:'mutt' does not show full subject'mutt' 没有显示完整的主题
【发布时间】:2015-05-02 07:52:11
【问题描述】:

我使用以下 shell 脚本发送电子邮件。但是邮件的主题总是显示“This”而不是"This is L_1.R"

    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 "zwang10@mtu.edu" -s' "This is "${program[0]}".R";

【问题讨论】:

    标签: linux shell ssh quoting mutt


    【解决方案1】:

    首先从您希望远程命令的外观开始,并使用最少的引用:

    echo the job L_1 is finished | mutt zwang10@mtu.edu -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 zwang10@mtu.edu -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 zwang10@mtu.edu -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 zwang10@mtu.edu -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 "zwang10@mtu.edu" -s "This is "'${program[0]}'".R";'
    • address="/home/campus27/zwang10/Desktop/AWRR/program/power/vmodel_1/nprot/K_10"
    • 我注意到你使用'"' '"'。你能解释一下吗?
    • 我把\n 放在echo 中,但它不起作用。 ssh -f ${host_list[0]} cd '"'$address'"' '&&' nohup Rscript ${program[0]}.R '>' ${program[0]}_sh.txt '&&' echo The job $address ${program[0]} \nis finished '|' mutt zwang10@mtu.edu -s "'"${host_list[0]} - Job ${program[0]}.R finished"'";
    • 你需要 echo 命令来得到一个文字反斜杠和 n,所以你需要为远程 shell 转义反斜杠,你还需要为本地 shell 转义它。所以'\\n'is finished 会起作用
    【解决方案2】:

    移动你的单引号。

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

    编辑:我把变量放在引号之外。主要是空间被覆盖了。

    【讨论】:

    • 我试过了,但它说program: Undefined variable.我没有在单引号内放双引号的原因是我无法在单引号之间定义变量。
    • 我将\n 放入echo,但它不起作用。 ssh -f ${host_list[0]} cd '"'$address'"' '&&' nohup Rscript ${program[0]}.R '>' ${program[0]}_sh.txt '&&' echo The job $address ${program[0]} \nis finished '|' mutt zwang10@mtu.edu -s "'"${host_list[0]} - Job ${program[0]}.R finished"'";
    猜你喜欢
    • 2017-02-13
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2015-01-13
    • 2011-07-22
    • 1970-01-01
    相关资源
    最近更新 更多