0

I have a file which have in every row email recipient,header and body . So the structure is like that:

receipient|header|body

[email protected],Alertheader,CheckYourData

[email protected],GreenLight,GoWithYourProcess

I would like to write a script which process every row and send an email to each person with header and body.

Please keep in mind that i am writing it on Informatica ETL tool (if that makes any difference)

So below script is working for sending email to 1 person from file(so file just have 1 email and nothing else),but got stuck on multiple persons and how to loop thru all those values.

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`

EDIT: I have this working with this script :)

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

But there is another thing i didnt anticipated .... In a body we can have commas so that would probably ruin my file.I was thinking to change delimiter in file to | . I tried to change IFS=| but that didnt work out. Any tips ?

2
  • What have you tried so far ? Commented May 30, 2020 at 16:35
  • @rafalbballer: the one-liner written by you doesn't prints "header" and "body" in the mail, it only prints the message given in your echo. is it the same what you want? Commented May 30, 2020 at 16:43

2 Answers 2

1

Consider the following to include the 'header' and 'body' from the file

IFS=',' while read email header body ; do
   if [ "$email" ] ; then
      mailx -s "$header" $mail <<< "$body"
   fi
done < /location/emailsrc.txt
Sign up to request clarification or add additional context in comments.

Comments

1

So while i posted it i almost immediatly found a solution :

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

1 Comment

Good job @rafalbballer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.