Bash linux 遍历文件并发送电子邮件

Bash linux loop throu file and send email

我有一个文件,每一行都有电子邮件收件人,header 和 body。 所以结构是这样的:

receipient|header|body

george@gmail.com,Alertheader,CheckYourData

rafal@gmail.com,GreenLight,GoWithYourProcess

我想编写一个脚本来处理每一行并用 header 和 body 向每个人发送一封电子邮件。

请记住,我是在 Informatica ETL 工具上编写的(如果这有什么不同的话)

所以下面的脚本可以从文件中向 1 个人发送电子邮件(因此文件只有 1 封电子邮件,没有其他任何东西),但卡在多人以及如何遍历所有这些值。

echo "Please check the session log in /ciwetl/SessLogs directory.CIW-SUPPORT TEAM" | mailx -s "CIW : Workflow wf_m_LOAD_CIW_LOCATION_RT failed." `cat /filelocation/emailsrc.txt`

编辑: 我用这个脚本工作:)

cat 'location/emailsrc.txt' | while IFS=, read -r line line2 || [[ -n $line ]]; do  echo $line2 | mailx -s "CIW : Workflow wf_m_LOAD_CIW_LOCATION_RT failed." $line; done

但是还有一件事我没想到.... 在 body 中,我们可以使用逗号,这样可能会破坏我的 file.I 正在考虑将文件中的分隔符更改为 | . 我试图改变 IFS=|但那没有成功。有什么建议吗?

所以当我发布它时,我几乎立即找到了解决方案:

cat '/location/emailsrc.txt' | while IFS='|', read -r line line2 || [[ -n $line ]]; do  echo $line2 | mailx -s "CIW : Workflow wf_m_LOAD_CIW_LOCATION_RT failed." $line; done

考虑以下内容以包含文件

中的'header'和'body'
IFS=',' while read email header body ; do
   if [ "$email" ] ; then
      mailx -s "$header" $mail <<< "$body"
   fi
done < /location/emailsrc.txt