I am fairly green using awk so I don't have anything started but what I am trying to do is: I have a file called "contacts" and in the file are 3 fields separate by ;. I want to read each line and send an email script. I have the email function working but just need to know how to setup awk to read each line and process. This is the sample of the contact file, it will grow so it will eventually have more than 3 lines
My goal is to read one line of the contacts and then send an email using $2 as the send to email address and a file attached to the email that would be unique for that email address. I know how to arrange the email script I just don't know how to write the awk script to read each line then send the email then read the next line and send an email until the end of the file. thanks
I tried to adapt that code you suggested but it continues to fail. my email script requires the \ slash to go at the end of each line and I think that is creating problems. The other variables you see below, $mr and $yr are passed from previous prompts in the script.
The above script results in nothing being sent and the email program giving an error about missing parameters. I have used the above email script without the ; separating each line and it works without the while statement added. Not sure how to continue each line but I believe that is the problem.
DON'T use exec - it will replace your current shell and you're ending up in nowhereland.
Are you sure you need that backslash (normally the "escape" char")? Are you sure you need that semicolon (shell's command end char)? Usual *nix syntax is to put all -options in a row, for a very long line you can use an "escaped <newline>" as a continuation char.
Try (without exec!) :
I have the script some what working. It will email the first statement but the next 2 it does not send but it includes them in the body of the first email on the first statement.
while IFS=";" read an addr name; do /u/star/sendEmail -f username@baby.net -t dzwic
k@ctc.net -s smtp.windstream.net:587 -xu username -xp password -u "statement" -a
/u/star/data/2013/04/"$an"0413.pdf
done < contacts
That's because the mail programs read the "mail body" from stdin which points to the remainder of contacts and thus eats away the two lines. Redirect mail's stdin to a standard text (or to e.g. /dev/null) and try again...