The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 06:08 AM
parse text file craggm Shell Programming and Scripting 9 02-27-2007 02:13 AM
parse text file klick81 Shell Programming and Scripting 3 12-18-2006 12:04 PM
How to redirect all mails to text file? redlotus72 UNIX for Dummies Questions & Answers 0 09-12-2006 12:27 AM
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 09:20 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-08-2006
Amruta Pitkar Amruta Pitkar is offline
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 !!!!!
  #2 (permalink)  
Old 08-08-2006
Dhruva's Avatar
Dhruva Dhruva is offline
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`
  #3 (permalink)  
Old 08-08-2006
Amruta Pitkar Amruta Pitkar is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 54
I am getting the following error
-f1:: not found
> Usage: uuencode [-m] [infile] remotefile
  #4 (permalink)  
Old 08-08-2006
Dhruva's Avatar
Dhruva Dhruva is offline
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?
  #5 (permalink)  
Old 08-08-2006
Amruta Pitkar Amruta Pitkar is offline
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.
  #6 (permalink)  
Old 08-08-2006
Dhruva's Avatar
Dhruva Dhruva is offline
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
  #7 (permalink)  
Old 08-09-2006
Amruta Pitkar Amruta Pitkar is offline
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
Closed Thread

Bookmarks

Tags
mailx, mailx attachment, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0