Parse Text file and send mails


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Parse Text file and send mails
# 1  
Old 08-08-2006
Parse Text file and send mails

Please help.

I have a text file which looks something like this

aaa@abc.com, c:FilePath\Eaaa.txt
bbb@abc.com, c:FilePath\Ebbb.txt
ccc@abc.com, c:FilePath\Eccc.txt
ddd@abc.com, c:FilePath\Eddd.txt...so on

I want to write a shell script which will pick up the first field 'aaa@abc.com' and store it in some memory variable say Field1.
Next I want to store c:FilePath\Eaaa.txt in Field2.
Finally I want to send a mail to Field1 with Field2 as an attachment.
I am new to Unix Shell scirpting and have no idea how to go about this !!!!!
# 2  
Old 08-08-2006
Try This script

Code:
for input_dir_row in `cat sample1.txt`
do
file_name=`echo $input_dir_row | cut -d ',' -f2`
mail_id=`echo $input_dir_row | cut -d ',' -f1`

SUBJ="Send mail from Unix with file attachments"
TO=$mail_id
(
cat << !
To : ${TO}
Subject : ${SUBJ}
!

cat << !
HOPE THIS WORKS
you got the mail from sendmail utility
!
uuencode $file_name $file_name
) | sendmail -v ${TO}
done

here sample1.txt is a input file which has email id and file names.you need to run this script from same dir where sample1.txt file is kept otherwise need to give path in for loop like
Code:
for input_dir_row in `cat /dirpath/sample1.txt`

# 3  
Old 08-08-2006
I am getting the following error
-f1:: not found
> Usage: uuencode [-m] [infile] remotefile
# 4  
Old 08-08-2006
are these files exist in the same machine from where you are running this script or exist on remote machine?

the file in which email id and file names are separated by comma (,) or some other delimiter?
# 5  
Old 08-08-2006
Hi dhruva

I have the sample input feedfile in the same location from where I am running the script. There is no problem with that.
the code is picking up the file name for the mail id.
File Name : Eaaa.txt
To : Eaaa.txt
The field delimiter is a comma followed by a space.
# 6  
Old 08-08-2006
can you check with echo what are the value coming in to variables
file_name and mail_id.
and replace the line
Code:
uuencode $file_name $file_name

by
Code:
uuencode -m $file_name $file_name

# 7  
Old 08-09-2006
Hi Dhruva

I tried ur newer suggestion :

set -x

for input_dir_row in `cat mailse1.lst`
do
file_name=`echo $input_dir_row | cut -f2`
mail_id=`echo $input_dir_row | cut -d ',' -f1`

SUBJ="Send mail from Unix with file attachments"
TO=$mail_id
(
cat << !
To : ${TO}
Subject : ${SUBJ}
!

cat << !
HOPE THIS WORKS
you got mail from sendmail utility
!

uuencode -m $file_name $file_name
) | sendmail -v ${TO}
done

Can u pls. explain what
cat << !
To : ${TO}
Subject : ${SUBJ}
!
does exactly.
From what I understand it assigns the To and Subject value and displays it on the screen.
But since the time I have been using the '-m' option with uuencode i cannot see these values on the screen.

What excatly is happening here ?

Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Postfix - Send mails to specific domains only

Hello, I am working on postfix server on CentOS 5.8 which will be send mails to a specific domain only. All the things are nearly finished but i am not getting how to setup the postfix to send mails to specific domains. Please help me out. Thanks, Sunny (2 Replies)
Discussion started by: sunnysthakur
2 Replies

2. Shell Programming and Scripting

Send Receive Mails

Hi All, I am writing one script to automate one long process. In this process we need to upload some input files and download some output files. So , I want to automate this upload and download by using mail functionality. I want to trigger this script when I am sending mail to server. I know... (0 Replies)
Discussion started by: NirajThakar
0 Replies

3. UNIX for Advanced & Expert Users

shell script to send separate mails to different users from a text file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: Code: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884... (0 Replies)
Discussion started by: giridhar276
0 Replies

4. UNIX for Advanced & Expert Users

Parse text file values and send those files as an attachment

We have these files in say \home\abcd\dm Summary.txt log_SI-100.lst log_SI-101.lst log_SI-106.lst The contents of Summary.txt is as below ./log_SI-100.lst:Error detected, rollbacking ./log_SI-101.lst:Error detected, rollbacking ./log_SI-106.lst:Error detected, rollbacking Now i... (5 Replies)
Discussion started by: depakjan
5 Replies

5. Red Hat

not able to send mails from linux

I am using centOS 5.3 as server, and i hav installed sendmail-8.13.8-2.el5.i386. But still, m not able to send mails to outer domain. Do i need to configure DNS for this? PLease suggest a step by step guide, if u hav, for the concern, as i m new to linux and sendmail as well.. thanks (1 Reply)
Discussion started by: oracle.test2
1 Replies

6. Shell Programming and Scripting

Read a file with in UNIX and send multiple mails

Hi-I want to create a shell script which should read a file line by line (file having email address and transaction id of each user)and send email on email ids with the transaction id of the user respectively. Please help - I think a while loop should help but I am very new too UNIX Shell... (1 Reply)
Discussion started by: DeepSalwan
1 Replies

7. Shell Programming and Scripting

parse the file and send email

Hi Experts, I am writing a script in which i want to parse the file and send the emails to some email-id's. The problem is like this-- I use to get some emails on saturday and sunday's but we do not work on these days. So what i want to do is forward those emails to some email id's. I want... (1 Reply)
Discussion started by: namishtiwari
1 Replies

8. AIX

Not able to send mails

Hi, I am not able to send mails to the recipents. I am using AIX 5.3 Version and using the below command. cat test.log|mail -s "TestMail" user1@mail.com Can you please tell me is there any configurations to be done or is the above command wrong? Thanks & Regards Sheshadri (3 Replies)
Discussion started by: arsheshadri
3 Replies

9. Debian

cannot send any mails using mailx

hi howto configure mailx ? kind regards ccc (11 Replies)
Discussion started by: ccc
11 Replies

10. UNIX for Dummies Questions & Answers

How to redirect all mails to text file?

Hi, I need to develop one application that reads all my mails (in unix mail box), and write into one txt file, My server is AIX .My mails are in AIX mail box. Any idea? (0 Replies)
Discussion started by: redlotus72
0 Replies
Login or Register to Ask a Question