Link to home
Start Free TrialLog in
Avatar of aixtutorial
aixtutorialFlag for United States of America

asked on

This is in AIX 5.3..I need a script

This is in AIX 5.3..I need a script..I have a file  data.txt

$cat data.txt
Agent No        E-mail
123                 abc@xyz.com
124                 abd@xyz.com
125                  abe@xyz.com  and so on

I need a script to read this file and send the e-mail with the Agent No
Example..Everyday at a partcular time,I need a script which reads throug the file and then send e-mail
in the above scenario,I want data.txt file to be read and an email to be sent

as Agent No 123 to abc@xyz.com  and Agent NO124 to abd@xyz.com  and so on






Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

try this

cat data.txt | while read line
do
   set $line
   echo You account No $1 | mailx -s "Your account No $1" $2
done
Avatar of Dave Gould
Dave Gould

or this:

while read -r agent email
do
  echo Your Agent is $agent | mailx -s "Agent Details" $email
done < data.txt

Avatar of aixtutorial

ASKER

The file type has changed abit ..The data.txt file looks like the below one right onow..Please provide the script for the below file as well

$cat data.txt
abc@xyz.com,HY321
abd@xyz.com,KL763
abe@xyz.com,BDC657

ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My first post doesn't need to be changed much. Just add the line "IFS="," and reverse the order of the read statement:

IFS=","
while read -r email agent
do
   echo Your Agent is $agent | mailx -s "Agent Details" $email
done < data.txt
worked