Operating System - HP-UX
1753518 Members
5182 Online
108795 Solutions
New Discussion юеВ

Re: Seperating data from a file

 
Dennis Handly
Acclaimed Contributor

Re: Seperating data from a file

>one email for one file, if it creates 100 files, it should send 100 emails. could you please tell me how to process?

for file in what-ever; do
mailx -s "${email_subject:?}" "${email_recipients[@]:?}" < $file
done
PK_1975
Frequent Advisor

Re: Seperating data from a file

Hi

u specified as

"for file in what-ever; do"

what-ever means?
I have to specify anything, could you please example

thanks
Dennis Handly
Acclaimed Contributor

Re: Seperating data from a file

>what-ever means? I have to specify anything, could you please example

You need to mention how you get those 100 files. If you do them one by one, then you can remove that for loop and just use $2.tmp.

If you are going to do them all at once, you will need to get a list of those files. Either from ls(1) or from a file. You need to be more specific where that mail command goes after you create the file(s).
TTr
Honored Contributor

Re: Seperating data from a file

Who is the email receipient for each PO file? Is it the person in the "Order Contact: " line or the person in the last "NOTES" line as in "NOTES: XXX FIRST LAST 856-xxx-yyyy"?
In that case you need to read each PO file and extract the name and then convert that to an email address based on whatever format you use.
Hein van den Heuvel
Honored Contributor

Re: Seperating data from a file

I guess we should have asked the old but valueable:
'WHAT PROBLEM ARE YOU REALLY TRYING TO SOLVE'.

WHY stick each order in a unique file, only to Email thme out? a SHELL or PERL script could just keep all data in memory and call mail directly from a sub-process feeding it the lines without ever needing a temp file to hold an order.

The AWK script could easily detect the new order condition END as well as the already present /^PURCHASE_ORDER_NO/ test, and then just do the Email of the past order right there and then, re-suing the same file (name) for the next order, renaming failed sends to a file to remain on the box with the order number in the file. Or in sticking with the unique names, perhaps delete succesfully send temp files.

HOW will you determine the "to:" Email address? Can that be integrated in the scripts? Perhaps a helper file with (phone) number to Email mapping?

Good luck!
Hein.


PK_1975
Frequent Advisor

Re: Seperating data from a file

Hi

Now I am able to send individual email for every individual file by the using the below code

for file in `ls /home/abc/*.tmp`
do
if test -s "${file:?}"
then
elm -s "${email_subject:?}" "${email_recipients[@]:?}" < $file
fi
done

Now I want to use only file name from the /home/abc directory and place that filename in the email subject for every email

the email subject should be like this "welcome abc.txt"

how can I place name of the file in the code could you please help me

Thanks
TTr
Honored Contributor

Re: Seperating data from a file

Before the elm line in your script, calculate the filename by using the basename command
filename=`basename $file`
elm -s "$filename" "${email_recipients[@]:?}" < $file
You can append or prepend any other text in the filename variable