The objective is to write a script that can read each line in the em.data file and send a corresponding email notification for each respective email account. Here vendor number 111111 will have different email account than vendor number 222222 and their line information will also differ.
What I have so far is the script below but it does differentiate between email addresses and sends all data to each respective email address. What would be some of your suggestions.
Looking at your script, presumably what you meant was `cut -f1 -d" "` to get your lists of values. This would still however be the wrong approach because you would end up with 5 variables, each containing ALL of the respective column data in your file.
You then say, for every element in $email (i.e. for each email address), mail them the full set of data held in $COLA, $COLB, $COLC and $COLD.
Do you see why this is wrong?
You need to take each line at a time. One way to do this is to use read:
while read COLA COLB COLC COLD EMAIL
mailx -s "Notifications" -r "$EMAIL firstname.lastname@example.org" <<- !!
$COLA $COLAB $COLAC $COLAD
done < em.data
Note that the spaces in front of $COLA is actually a TAB (The use of <<- allows this formatting and will remove the TAB before passing the detail into mailx).
Last edited by Damian Ibbotson; 01-30-04 at 12:19.
The file em.data is placed after the loop because the loop is taking its input from that file.
while read lineDataFromFile
done < fileName
What this is saying is 'while' the exit status of the read command is 0 (i.e. the read command returns 'true') after attempting to read the next line from the file em.data, attempt to read another line. When there are no more lines to read, the final attempt to read a line will fail and return a non-zero exit status (which equates to a boolean false) and the loop will cease. It's a simple case of "while condition=true; do stuff".