We help IT Professionals succeed at work.

This is in AIX 5.3..I need a script

aixtutorial
aixtutorial asked
on
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






Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
try this

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

Commented:
or this:

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

Author

Commented:
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

CERTIFIED EXPERT
Top Expert 2007
Commented:
try

awk -F ',' '{ print $1 " " $2 } ' data.txt | while read line
do
 set $line
   echo You account No $2 | mailx -s "Your account No $2" $1
done
Dave GouldOnsite Support

Commented:
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

Author

Commented:
worked

Explore More ContentExplore courses, solutions, and other research materials related to this topic.