Bash linux通过文件循环并发送电子邮件

问题描述 投票:0回答:2

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

receipient|header|body

[email protected],Alertheader,CheckYourData

[email protected],GreenLight,GoWithYourProcess

我想编写一个脚本来处理每一行,并通过抬头和正文向每个人发送电子邮件。

[请记住,我正在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

但是还有我没想到的另一件事...。在主体中,我们可以使用逗号,以免破坏文件。我当时正在考虑将文件中的定界符更改为|。 。我试图更改IFS = |但这没有解决。有提示吗?

linux bash scripting informatica
2个回答
0
投票

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

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

0
投票

请考虑以下内容,以包含文件中的'标题'和'正文'

IFS=',' while read email header body ; do
   if [ "$email" ] ; then
      mailx -s "$header" $mail <<< "$body"
   fi
done < /location/emailsrc.txt
© www.soinside.com 2019 - 2024. All rights reserved.