The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parse through one text file and output many sophiadun UNIX for Dummies Questions & Answers 14 02-20-2008 03:08 AM
parse text file craggm Shell Programming and Scripting 9 02-26-2007 11:13 PM
parse text file klick81 Shell Programming and Scripting 3 12-18-2006 09:04 AM
How to redirect all mails to text file? redlotus72 UNIX for Dummies Questions & Answers 0 09-11-2006 09:27 PM
How to parse a text file with \034 as field and \035 as end of message delimiter? indianya Shell Programming and Scripting 1 08-26-2005 06:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-07-2006
Registered User
 

Join Date: Aug 2006
Posts: 54
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 !!!!!
Reply With Quote
Forum Sponsor
  #2  
Old 08-08-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 255
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`
Reply With Quote
  #3  
Old 08-08-2006
Registered User
 

Join Date: Aug 2006
Posts: 54
I am getting the following error
-f1:: not found
> Usage: uuencode [-m] [infile] remotefile
Reply With Quote
  #4  
Old 08-08-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 255
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?
Reply With Quote
  #5  
Old 08-08-2006
Registered User
 

Join Date: Aug 2006
Posts: 54
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.
Reply With Quote
  #6  
Old 08-08-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 255
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
Reply With Quote
  #7  
Old 08-09-2006
Registered User
 

Join Date: Aug 2006
Posts: 54
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
mailx, mailx attachment, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0