Search code examples
linuxshellsshquotingmutt

'mutt' does not show full subject


I use following shell script to send email. But the subject of email always shows "This" instead of "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";

Solution

  • First start with what you want the remote command to look like, with bare minimal quoting:

    echo the job L_1 is finished | mutt zwang10@mtu.edu -s 'This is L_1.R'
    

    There are only a couple of things you need to quote to have them passed literally to the remote shell: the pipe character, and quotes around the subject to make the spaces not split it into separate arguments to 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"'";
    

    With the longer command, do the same thing:

    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'
    

    (only with the variables substituted).

    Here, a few things need to be quoted:

    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"'"