How to attach two files in unix script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to attach two files in unix script
# 8  
Old 12-07-2010
did you try as suggested in post #4 ?
# 9  
Old 12-07-2010
Yes....but it dint work as expected.....the file contents are available in the body of the email and they are not reffered as a separate attachment.
# 10  
Old 12-07-2010
Make sure that the client you use to open an read the email, doesn't have an activated option to put attachement as 'inline text' (i think there is such an option in Thunderbird for example).
# 11  
Old 12-07-2010
Can you please let me know i how can i implement through script for sending an email with two attachments.
# 12  
Old 12-07-2010
I have tried your code as well which works fine except for one thing. Assuming 'Hi' is not a file, you could use echo to instead of cat.
Code:
( echo Hi; uuencode "$File1" "$File1"; uuencode "$File2" "$File2") | mail -s "attachment" abc@xyz.com

As suggested by ctsgnb there could be problem in your email client. However can you post your full code..
# 13  
Old 12-07-2010
This is my code

Code:
#! /bin/ksh
export EMAILLIST="abc@xyz.com"
cd /home2/data
File1=`ls -lrt *_Accepted.* | tail -1 | awk '{print ($9)}'`
File2=`ls -lrt *_Rejected.* | tail -1 | awk '{print ($9)}'`
echo $File1
echo $File2
SUBJECT="Two Attachment Email"
BODY="Kindly refer the attachment" > /home2/data/email_body.txt
# send an email using /bin/mail
(cat /home2/data/email_body.txt; uuencode "$File1" "$File1"; uuencode "$File2" "$File2") | mail -s "$SUBJECT" $EMAILLIST

Expected Result:
Quote:
Email should be recieved with two attachments and the email body should only contain "Kindly refer the attachment"
Actual Result:
Quote:
Email is recieved with no attachments and the file contents are printed in the email boby and it looks like as shown below
Kindly refer the attachment
aa bb cc(file1 content)
dd ee ff(file2 content)
# 14  
Old 12-07-2010
Code:
File1=`ls -lrt *_Accepted.* | tail -1 | awk '{print ($9)}'`
File2=`ls -lrt *_Rejected.* | tail -1 | awk '{print ($9)}'`

could be shorten
Code:
File1=`ls -rt *_Accepted.* | tail -1`
File2=`ls -rt *_Rejected.* | tail -1`

Code:
echo $File1
echo $File2

are useless (except for interactively controlling the variable have correctly been assigned but echo $File1 $File2 would do the work as well

You could also have a look at this thread, maybe you are experiencing the same kind of problem.
Give a try to the following :
run your script, but change the email address, send it to some external mail address like something@gmail.com adress or any other mail provider, and check how you get your attachment (attached or inline text ?).

I think your script is ok, i suspect the problem is on the reception-side.

Last edited by ctsgnb; 12-07-2010 at 09:25 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Attach filename to wc results on massive number of files

Hello, I have massive number of big files that needed to be counted for the total number of lines (> 100x millions) each. I want the file name attached to the count results so that they are aligned nicely matching name and counts. I could do each file at a time, which will take hours to finish,... (8 Replies)
Discussion started by: yifangt
8 Replies

2. Shell Programming and Scripting

Script to attach latest files of directories in a mail.

Hello Folks, I am looking for the script which will go to directory and check for the latest 5 files and send a mail to attaches these files to user. Kindly guide. Regards (7 Replies)
Discussion started by: sadique.manzar
7 Replies

3. Shell Programming and Scripting

UNIX - how to send attach excel in mail

Hi Experts, i need your help here :confused: Need to send a report thru mail using unix shell script(AIX). can you help me to do this? . i tried "uuencode" with CSV format, but while reading report all values are in single column. i need each column values in separate cell. Thanks in... (9 Replies)
Discussion started by: newbieabc
9 Replies

4. Shell Programming and Scripting

How to attach multiple .csv files using mutt command

I need to attach all files starting with 'BusinessReport' using mutt command. It could be any number of files in that directory, say BusinessReport_01, BusinessReport_03, BusinessReport_04 etc. Is there a way to attach all files where filename like BusinessReport_* and sent it using mutt... (2 Replies)
Discussion started by: Jassz
2 Replies

5. Shell Programming and Scripting

Script to attach file to mail

Hello, I have a .dat file containing one line. I need a script to read that line and make it part of the body and send a mail... Let's say the line is $line. I need the script to send a mail with the body "The last disposal feed is $line". Thanks (4 Replies)
Discussion started by: sfetea
4 Replies

6. Shell Programming and Scripting

Attach a binary file to email in a script

Hi, I am trying to get an email sent out by the unix ( aix ) system that has a .gz file attached to it. I can get the attachment, but it's not working when being looked at from outlook. I think there is a problem because of the way I am doing it, and the fact that it's binary. I am trying to... (15 Replies)
Discussion started by: fwellers
15 Replies

7. Shell Programming and Scripting

attach multiple files in email

I am trying to send multiple files as attachment in one email, I tried to search but couldn't find. Please let me know if any solutions. (2 Replies)
Discussion started by: mgirinath
2 Replies

8. Shell Programming and Scripting

attach 2 files using mailx

if test.dat is the file cat test.dat|uuencode test.dat|mailx -s "subject" mailid can be used for attaching test.dat how can i attach more than one file to a mail using mailx (2 Replies)
Discussion started by: anumkoshy
2 Replies

9. UNIX for Advanced & Expert Users

pine does'nt attach files

Hello All, I am maintaining a server and I use pine as MUA and sendmail as MTA. Suddenly many users in the network face the problem of not being able to attach files using pine. I checked the sendmail.cf file and found a variable "MaxMessageSize = 1000000". Eventhough the message size... (2 Replies)
Discussion started by: maybemedic
2 Replies
Login or Register to Ask a Question