Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash循环将一些文本附加到文件并发送邮件_Bash_Email_While Loop - Fatal编程技术网

bash循环将一些文本附加到文件并发送邮件

bash循环将一些文本附加到文件并发送邮件,bash,email,while-loop,Bash,Email,While Loop,我试图编写一个bash“while循环”,从输入文件中获取输入,并将这些输入添加到邮件模板中,然后向用户发送邮件 当我尝试此操作时,邮件模板被覆盖(出于明显的原因),脚本为第二次发送的第二封邮件包含脚本为第一次迭代附加的详细信息 如何修改我的脚本,以便对于每个输入,脚本获取详细信息,将其添加到邮件模板中,并向用户发送邮件,而原始邮件模板保持不变 这是我的剧本 while read -r i do cat >> MAILTEMPLATE.txt <<EOF

我试图编写一个bash“while循环”,从输入文件中获取输入,并将这些输入添加到邮件模板中,然后向用户发送邮件

当我尝试此操作时,邮件模板被覆盖(出于明显的原因),脚本为第二次发送的第二封邮件包含脚本为第一次迭代附加的详细信息

如何修改我的脚本,以便对于每个输入,脚本获取详细信息,将其添加到邮件模板中,并向用户发送邮件,而原始邮件模板保持不变

这是我的剧本

while read -r i
do
    cat >> MAILTEMPLATE.txt <<EOF
    #Some text that i need to append to the MAILTEMPLATE.txt file for the specific input
    EOF
    cat MAILTEMPLAT.txt|mail emp@org.com
done<inputfile
读取时-r i
做
cat>>MAILTEMPLATE.txt在下,您可以在不需要临时文件的情况下执行此操作:

.1使用您的语法:
读取时-r i
做

cat MAILTEMPLATE.txt-不要附加到模板文件本身
cat
模板和添加到新文件中的内容,然后将其删除。终止的
EOF
so#Reisner,您认为应该这样做吗。。在不需要的情况下读取-r i do cp MAILTEMPLATE.txt newfile.txt cat>>newfile.txt@EtanReisner newfile.txt,您可以:
mailemp@org.com <
while read -r i
do
    cat MAILTEMPLATE.txt - <<-EOF | mail emp@org.com
        #Some text that i need to append to the MAILTEMPLATE.txt file for the specific input
        EOF
done <inputfile
buildMail() {
    cat MAILTEMPLATE.txt - <<-eof
        This is appended to mail body
        Where $1 is 1st arg of buildMail function
        $2 second and $@ is whole args list.
        eof
}

while read -r i ;do
    buildMail "$i" Other arg may be used... |
        mail emp@org.com
done< inputfile