Parse Text file and send mails


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Parse Text file and send mails
# 8  
Old 08-10-2006
It looks like your problem is here:
Code:
for input_dir_row in `cat mailse1.lst`
do

Your field delimiter is a comma followed by a space, and the shell is splitting up the output of 'cat' based on whitespace, not newline characters. Your variable 'input_dir_row' is assigned a new value for each consecutive sequence of characters in the file.

For example,

Code:
for i in `cat sample.txt` ; do
  echo X${i}X
done

Xaaa@abc.com,X
Xc:FilePath\Eaaa.txtX
Xbbb@abc.com,X
Xc:FilePath\Ebbb.txtX
Xccc@abc.com,X
Xc:FilePath\Eccc.txtX
Xddd@abc.com,X
Xc:FilePath\Eddd.txtX

You could using something like 'read' instead.

Code:
cat sample.txt | while read i ; do
  mail_id=`echo $i | awk -F',' '{print $1}'`
  filename=`echo $i | awk -F',' '{print $2}'`

  echo "mail_id = $mail_id , filename = $filename"

done

mail_id = aaa@abc.com , filename =  c:FilePathEaaa.txt
mail_id = bbb@abc.com , filename =  c:FilePathEbbb.txt
mail_id = ccc@abc.com , filename =  c:FilePathEccc.txt
mail_id = ddd@abc.com , filename =  c:FilePathEddd.txt

And be sure to remember the filename here still has a space character preceding it.
# 9  
Old 08-10-2006
Hi Nathan

Meanwhile, before reading ur suggestion, I was working on the script....

I have solved the error in the following manner :
FILENAME="$1"

cat $FILENAME | while read LINE
do
echo "$LINE"
FileName=`echo $LINE | cut -f2 -d' '`
echo $FileName
MailId=`echo $LINE | cut -f1 -d' '`
echo $MailId
done

Now the FileName and the MailId are recd correctly.
Now my assignemtn is to Mail the FileName to the MailId.
1) First I just want to send a mail.
2) If possible maybbe....send it as an attachment.

Thanks
Amruta Pitkar
# 10  
Old 08-10-2006
Try using 'mail' ( "man mail" should help ). I would also check and see if elm, pine, and/or mutt are installed on your system. The command line options to send mail using these are pretty easy.

Code:
echo hello | mail user@host

# 11  
Old 08-10-2006
I tried to send the file using the foll command
cat e62581.txt | mailx -s"Trying Attachment" aar@yahoo.com
it worked.
(**** Filename is e62581.txt.)

But wheen I tried to cat the same file using 'uuencode e62581.txt e62581.txt' | mailx -s"Trying Attachment" aaar@yahoo.com.
It displayed the following error :
+ read LINE
+ echo aar@yahoo.com e62581.txt
aar@yahoo.com e62581.txt
+ + cut -f2 -d
+ echo aar@yahoo.com e62581.txt
FileName=e62581.txt
+ echo e62581.txt
e62581.txt
+ + cut -f1 -d
+ echo aar@yahoo.com e62581.txt
MailId=aar@yahoo.com
+ echo aar@yahoo.com
aar@yahoo.com
+ e62581.txte e62581.txt
+ mail -s Attachments aar@yahoo.com
: No such file or directory
Null message body; hope that's ok
Why So ...Any Idea...can u suggest where am I going wrong ??
# 12  
Old 08-10-2006
modofied the script.care to run this script? if get any errror message let us know .....if it gives error with uuencode -m then add -m option.if sendmail wont work we will replace it with mailx

Code:
while read input_dir_row
do
file_name=`echo $input_dir_row | cut -d ',' -f2`
mail_id=`echo $input_dir_row | cut -d ',' -f1`
echo $file_name
echo $mail_id

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<sample1.txt

# 13  
Old 08-11-2006
Creating Mail Error Log and Attachment

Hi there
I solved the problem...Now I can send mail using the mail command to everybody.
Code:
#!/usr/bin/ksh

set -x

FILENAME="$1"

cat $FILENAME | while read LINE
do
        echo "$LINE"
        FileName=`echo $LINE | cut -f2 -d' '`
        echo $FileName
        MailId=`echo $LINE | cut -f1 -d' '`
        echo $MailId
        /PATH/Project/$FileName| mail -s "Sending mail" $MailId
done

1)Now my question is I want to create an ErrorLog for all the outbound emails.
And check them for Invalid User, User MailBoxFull, Success.
I think with sendmaill we can avail the Exit return Status...but then can we achieve the same with mail ?
2)When I am using uuencode to send attachements...I recv junk on my yahoo user id, from my local id. However when I send a mail to myself on local system , I recv it as an attachment ...any idea why ?
Thanks
Amruta Pitkar
 
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