Sending email with multiple files..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending email with multiple files..
# 8  
Old 11-01-2010
To send multiple files, try ...

(uuencode file1 file1;uuencode file2 file2)|mailx -s "subject" your_email@domain.com

Man uuencode.

Hope that helped.
# 9  
Old 11-01-2010
Quote:
Originally Posted by methyl
Lots of questions:
Some of the critical variables are not written to by the script as posted.

What should be in $subject ?
Doesn't matter
What should be in $to ?
mailx -s "$subject" "$to" id11355@gmail.com
What should be in $logfile, $logfile1 $logfile2 $logfile3 .
When the data is loaded, it generates a log file. The log file is stored in a directory called "space/dbexport/PHR/log/abc.log". This path can be sent to the user's, but some user may or may not have access to view the file. So the best way is to send the log file itself to the user as a text file attachment. The user can open the attachment and view the details.


Imagine I was to receive the email.
What should be in the email subject?
Yes, you are right.. But as per the specification, Subject should not matter here.
What should be in the email body?
Nothing
What should be in the email attachments?
Log file as attachments (log.txt).

Assuming M$ email client, what software should I use to open the attachments? Hint: filename.txt is opened by notepad. filename.log causes a question.
filename.txt

---------- Post updated at 21:47 ---------- Previous update was at 21:44 ----------

@DGPickett
Your solution is syntactically incorrect and naive guesswork.
# 10  
Old 11-01-2010
Quote:
Originally Posted by kevinarmstrong
To send multiple files, try ...

(uuencode file1 file1;uuencode file2 file2)|mailx -s "subject" your_email@domain.com

Man uuencode.

Hope that helped.
You can have a message, too. While saying the file name twice adds the name, it is counterintuitive and a bit scary to say write my input, and hardly necessary for such as small payback. You can send files compress'ed, gzip'ed, even bzip2'ed or rar'ed for shorter text:
Code:
(
 echo 'your
            message'
 
 echo Begin embedded files:
 
 echo
 echo file1.gz ==============
 echo
 gzip -9 < file1 | uuencode -
 
 echo
 echo file2.gz ==============
 echo
 gzip -9 < file2 | uuencode -
 
 echo
 echo ===== END =====
 ) | mailx -s "subject"

# 11  
Old 11-01-2010
I tried this, but it did'nt work.
I twisted the script a bit, and i am getting the output as
Code:
/SPACE/DBEXPORT/PHR/DATA/CONDITION: 2000
log file path is:

/space/dbexport/PHR/log/condition-20101101.log

/space/dbexport/PHR/log/encounter-20101101.log

/space/dbexport/PHR/log/procedure-20101101.log

/space/dbexport/PHR/log/provider-20101101.log

========= END =======
/SPACE/DBEXPORT/PHR/DATA/ENCOUNTER: 1000
log file path is:

/space/dbexport/PHR/log/condition-20101101.log

/space/dbexport/PHR/log/encounter-20101101.log

/space/dbexport/PHR/log/procedure-20101101.log

/space/dbexport/PHR/log/provider-20101101.log

========= END =======

I want the output to be displayed as shown below:
/SPACE/DBEXPORT/PHR/DATA/CONDITION: 2000
log file path is:
/space/dbexport/PHR/log/condition-20101101.log

/SPACE/DBEXPORT/PHR/DATA/ENCOUNTER: 1000
log file path is:
/space/dbexport/PHR/log/encounter-20101101.log


/SPACE/DBEXPORT/PHR/DATA/PROCEDURE: 1000
log file path is:

/space/dbexport/PHR/log/procedure-20101101.log

/SPACE/DBEXPORT/PHR/DATA/PROVIDER: 150
log file path is:
/space/dbexport/PHR/log/provider-20101101.log

The shell script is:
Code:
(
echo "CONDITION, ENCOUNTER & PROCEDURE LOAD PROCESS FINISHED SUCCESSFULLY."
echo "Input file path and the total records it contains and loaded into the table's are shown below."
echo "________________________________________________________________________"
for filename in /space/dbexport/PHR/data/conditionExport_test.csv /space/dbexport/PHR/data/encounterExport.csv /space/dbexport/PHR/data/procedure
Export.csv /space/dbexport/PHR/data/providerExport.csv
do
# get description from filename, convert to uppercase
#
desc=$(echo $filename|sed 's/Export.*csv//'|tr '[a-z]' '[A-Z]')
# get total record count from file
#
n=$(wc -l < $filename)
echo "$desc: $n"
echo "log file path is:"
echo
echo /space/dbexport/PHR/log/condition-`date +%Y%m%d`.log
echo
echo /space/dbexport/PHR/log/encounter-`date +%Y%m%d`.log
echo
echo /space/dbexport/PHR/log/procedure-`date +%Y%m%d`.log
echo
echo /space/dbexport/PHR/log/provider-`date +%Y%m%d`.log
echo
echo ========= END =======
done
) | mailx -s "$subject" "$to" id11355@gmail.com

---------- Post updated at 11:01 AM ---------- Previous update was at 10:59 AM ----------

Quote:
Originally Posted by msrahman
I tried this, but it did'nt work.
I twisted the script a bit, and i am getting the output as
/SPACE/DBEXPORT/PHR/DATA/CONDITION: 2000
log file path is:

/space/dbexport/PHR/log/condition-20101101.log

/space/dbexport/PHR/log/encounter-20101101.log

/space/dbexport/PHR/log/procedure-20101101.log

/space/dbexport/PHR/log/provider-20101101.log

========= END =======
/SPACE/DBEXPORT/PHR/DATA/ENCOUNTER: 1000
log file path is:

/space/dbexport/PHR/log/condition-20101101.log

/space/dbexport/PHR/log/encounter-20101101.log

/space/dbexport/PHR/log/procedure-20101101.log

/space/dbexport/PHR/log/provider-20101101.log

========= END =======

I want the output to be displayed as shown below:
/SPACE/DBEXPORT/PHR/DATA/CONDITION: 2000
log file path is:
/space/dbexport/PHR/log/condition-20101101.log

/SPACE/DBEXPORT/PHR/DATA/ENCOUNTER: 1000
log file path is:
/space/dbexport/PHR/log/encounter-20101101.log


/SPACE/DBEXPORT/PHR/DATA/PROCEDURE: 1000
log file path is:

/space/dbexport/PHR/log/procedure-20101101.log

/SPACE/DBEXPORT/PHR/DATA/PROVIDER: 150
log file path is:
/space/dbexport/PHR/log/provider-20101101.log

The shell script is:
(
echo "CONDITION, ENCOUNTER & PROCEDURE LOAD PROCESS FINISHED SUCCESSFULLY."
echo "Input file path and the total records it contains and loaded into the table's are shown below."
echo "________________________________________________________________________"
for filename in /space/dbexport/PHR/data/conditionExport_test.csv /space/dbexport/PHR/data/encounterExport.csv /space/dbexport/PHR/data/procedure
Export.csv /space/dbexport/PHR/data/providerExport.csv
do
# get description from filename, convert to uppercase
#
desc=$(echo $filename|sed 's/Export.*csv//'|tr '[a-z]' '[A-Z]')
# get total record count from file
#
n=$(wc -l < $filename)
echo "$desc: $n"
echo "log file path is:"
echo
echo /space/dbexport/PHR/log/condition-`date +%Y%m%d`.log
echo
echo /space/dbexport/PHR/log/encounter-`date +%Y%m%d`.log
echo
echo /space/dbexport/PHR/log/procedure-`date +%Y%m%d`.log
echo
echo /space/dbexport/PHR/log/provider-`date +%Y%m%d`.log
echo
echo ========= END =======
done
) | mailx -s "$subject" "$to" id11355@gmail.com

Note: The user should get the log file path along with the log file as an attachment of all the 4 files. The attachment can be a .txt file too.

Last edited by Scott; 11-01-2010 at 04:44 PM.. Reason: Code tags again...
# 12  
Old 11-01-2010
Well, I guess in the loop you need to extract the variable component that matches the log out, to select just one log to report on:
Code:
 
logname=$(filename##*/}
logname=/space/dbexport/PHR/log/${logname%Export*}-`date +%Y%m%d`.log

Narrative: First, set the logname to the entry name of the file, temporarily (pound on the nose, aggressively, down to a slash), then reset it to the logdir/entry-name-less-Export-and following (percent is chew on the right end, like a writer getting his % in the end, up to Export)-date -and-suffix.
# 13  
Old 11-01-2010
I didn't quite understand your reply back.

Can you pls explain it to me using my script, as to where the changes needs to be done.
This is getting too confused...
# 14  
Old 11-01-2010
After a log of twiddling around I found that my version of "mailx" did not like alternating free text and attachments. We need to output any free text first, then add the attachments.
Also I needed the "-m" switch to "mailx".

The O/P omits to mention which O/S so my attempt may need some syntax changes for whatever O/S we have here.

Ignoring the various specification changes and finer points of layout, this is a reply to post #1 about getting the free text and attachments in the same mail whilst avoiding numerous undefined variables.

Code:
logfile1="/space/dbexport/PHR/log/condition-`date +%Y%m%d`.log"
logfile2="/space/dbexport/PHR/log/encounter-`date +%Y%m%d`.log"
logfile3="/space/dbexport/PHR/log/procedure-`date +%Y%m%d`.log"
logfile4="/space/dbexport/PHR/log/provider-`date +%Y%m%d`.log"
touch "${logfile1}"
touch "${logfile2}"
touch "${logfile3}"
touch "${logfile4}"
subject="CONDITION, ENCOUNTER & PROCEDURE LOAD PROCESS FINISHED SUCCESSFULLY."
(
echo "Input file path and the total records it contains and loaded into the tables are shown below."
for logfile in "${logfile1}" "${logfile2}" "${logfile3}" "${logfile4}"
do
    # get description from filename, convert to uppercase
    #
    desc=$(echo "${logfile}"|sed 's/Export.*csv//'|tr '[a-z]' '[A-Z]')
    # get total record count from file
    #
    n=$(wc -l < "${logfile}")
    echo "$desc: $n"
    echo "log file path is: ${logfile}"
done
for logfile in "${logfile1}" "${logfile2}" "${logfile3}" "${logfile4}"
do

    attachment=`basename "${logfile}"`.txt
    ux2dos "${logfile}"|uuencode "${attachment}"
    echo ""
done
) | mailx -m -s "${subject}" id11355@gmail.com


Last edited by methyl; 11-01-2010 at 02:46 PM.. Reason: Onitted "-m"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending multiple files using uuencode command

Hi All, I want to send multiple CSV file using below code. In Result folder, we have multiple CSV files. However, I want to catch only Summary CSV files. I was trying using *, % with different combination. However, not able to do so. From below code, I could send only one file... (1 Reply)
Discussion started by: Swapnil Mawle
1 Replies

2. Shell Programming and Scripting

Sending files to multiple emails

Hi All, I want to send each file to each email id as below. Instead of writing saparate 10 mail commands can we do it in a simple step. file1.csv to raghu.s@hps.com file2.csv to kiran.m@hps.com file3.csv to kenni.d@hps.com file4.csv to rani.d@hps.com file5.csv to sandya.s@hps.com... (2 Replies)
Discussion started by: ROCK_PLSQL
2 Replies

3. Solaris

Sending Mails to the Multiple Email Address

Hi All, I am pretty new to the mail service in Sun Solaris 5.10. If anybody help me in writing a script for the multiple recipient with subject and the body would be a helpful. Kindly help... Thanks in advance. :) Warm Regards, Pramod (5 Replies)
Discussion started by: Pramod_009
5 Replies

4. Shell Programming and Scripting

sending multiple files along with mail message using uuencode

Hi, I have a requirement to send a mail with multiple files attached to it and along with the text message in the mail. I am trying sumthing like below but it only sends me the text message and no files attached to the mail. ---------------------------------------- ( uuencode file1... (1 Reply)
Discussion started by: sachinkl
1 Replies

5. UNIX for Dummies Questions & Answers

Zipping files and sending email

Hi, I need to zip 4 files and send an email attaching the zipped files... Pls help.. Win ---------- Post updated at 10:49 AM ---------- Previous update was at 10:36 AM ---------- Hi, I need to convert 4 text files into xls,zip these 4 files and send an email attaching the... (2 Replies)
Discussion started by: win4luv
2 Replies

6. HP-UX

Sending email to multiple IDs

Hi, I am trying to send an email to multiple IDs from Unix script. I have given the EmailIds in a file and trying to use the file as input in the script. > cat Email EmailID = "abc@xyz.com cbz@xyz.com" In my script I have . /Email mailx -s "subj" $EmailID This fails with the... (3 Replies)
Discussion started by: sangharsh
3 Replies

7. HP-UX

Sending Unix files as attachments in an email

Hi, I am executing the following command in order to send a file as an attachment: mailx -s "Subject" emailID@xyz.com < Testfile.txt Instead of attaching the file Testfile.txt, it is writing the contents of the file in the email message body. Please advise on how I can send the file as an... (7 Replies)
Discussion started by: sangharsh
7 Replies

8. Shell Programming and Scripting

Sending an email with more than one files

Hi, I would like to send an email with more than one attachement. I am using uuencode. I want to achive by suing uuencode. Also please let me know other ways. -Thambi (7 Replies)
Discussion started by: thambi
7 Replies

9. Shell Programming and Scripting

Sending mutiple files thru email to lotus notes

Hi All, I am currently using the following script to send the single file to one/more email addresses. I need to send mutilple files at same time, are there anyway I could modify the script or write new one to accomplish the same. Script *************** #!/bin/ksh # Author: Manish... (4 Replies)
Discussion started by: lapisguy
4 Replies

10. Shell Programming and Scripting

Sending Multiple Files through email

Hi Everyone, I'm using the uuencode command with the mail command to send out emails through a UNIX script. The problems is that i have a number of gif files that i need to attach to a single email but the number and name of the gif files is not static. Example today the folder home/Desktop may... (4 Replies)
Discussion started by: nbvcxzdz
4 Replies
Login or Register to Ask a Question