Sending email with multiple files..

Hello,,
I am loading data into the 4 tables from 4 different input files.
The data gets loaded, and the e-mail is also sent to the user, but the log files for all the 4 files is not been sent..

I am trying to send e-mail to users with the log file as attachment.

The script is as follows:

logfile="/space/dbexport/PHR/log/condition-`date +%Y%m%d`.log"
logfile1="/space/dbexport/PHR/log/encounter-`date +%Y%m%d`.log"
logfile2="/space/dbexport/PHR/log/procedure-`date +%Y%m%d`.log"
logfile3="/space/dbexport/PHR/log/provider-`date +%Y%m%d`.log"
touch $logfile
touch $logfile1
touch $logfile2
touch $logfile3

 
(
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."
for filename in /space/dbexport/PHR/data/conditionExport_test.csv /space/dbexport/PHR/data/encounterExport.csv /space/dbexport/PHR/data/procedureExport.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 "$logfile", "$logfile1", "$logfile2", "$logfile3"
echo ""
done
) /space/dbexport/PHR/log/uuencode $logfile, $logfile1, $logfile2, $logfile3 | mailx -s "$subject" "$to" id11355@gmail.com 

Can any one please help me as to how to send log files for all the 4 tables loaded as attachment?

Regards

Before we start.
Please make sure that any other threads you may have open on this subject contain a clear pointer to this thread.

All other threads closed.

First, logfiles are just text, so you could just append them into the body of the email. If they must be attachments, you need a more sophisticated mail client.

(
 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."
for filename in /space/dbexport/PHR/data/conditionExport_test.csv /space/dbexport/PHR/data/encounterExport.csv /space/dbexport/PHR/data/procedureExport.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 "$logfile", "$logfile1", "$logfile2", "$logfile3"
echo ""
done

 for log in logdir/*.YYYYMMDD.*
 do
  echo ============== ${log~~*/} ====================
  cat $log
  echo
  echo =========================================
  echo
done | mailx -s "$subject" "$to" id11355@gmail.com

Lots of questions:
Some of the critical variables are not written to by the script as posted.

What should be in $subject ?
What should be in $to ?
What should be in $logfile, $logfile1 $logfile2 $logfile3 .

Imagine I was to receive the email.
What should be in the email subject?
What should be in the email body?
What should be in the email attachments?

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.

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

@DGPickett
Your solution is syntactically incorrect and naive guesswork.

It is cheaper to send URLs and make the logs visible on a web server. People who get the email and do no have so much interest will skip them.

But methyl is right, notepad will open any URL ending in '.txt', so your logs might need carriage returns and different names.

If you create a simple web service, you can process and deliver them as <PRE> text (you have to take care of any <>'"& in the text, & first as they become '>', . . . '&' so the & processing would mangle the '>' ! Saw it overdone online just this week somewhere, � on the web page! :smiley:

The script has a fundamental design problem because it does not match the ".log" filenames to the ".csv" filenames.

In fact on careful examination I cannot determine what the ".log" files are for. At the start of the script the are blank files (I think) and nothing in the script writes to them. Perhaps they are the intended as the names for email attachments? Who knows?

It is fairly straightforward to convert each ".csv" filename to the corresponding ".log" filename. The only variable text is in the filename pairs is "condition/encounter/procedure/provider".

Let's see how the O/P maps the input to the expected output, not forgetting filling in the contents of $subject and $to .

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:

(
 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" 

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

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

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.

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:

 
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.

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

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.

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

Thanks for the reply methyl,
I ran the script and i am getting this error:

Commit point reached - logical record count 64
Commit point reached - logical record count 128
Commit point reached - logical record count 150
mailx: illegal option -- m
Usage: mailx -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address
                -s SUBJECT -f FILE users
Condition table load Failed -- Return Code=1
-bash-3.00$

Can you explain to me as to what "-m" does here in the code?

I have several files with format 2010_10_30_abc.txt,2010_10_30_abc.csv......
and I have to remove files older than 56 days as in date with file name not the load time becuase some of the files are there from last year. So we copy file every week and keep them for 56 days and will delete after 56 days.

I am doing like this:

cd ${TGT_PATH}
if [ $? = 0 ]
then
        find . -type f  -atime +56 -exec rm -f {} \; -print > Deleted_Files_Older_Than_8W.log
fi

This is not working.

Really, it should be like this, starting with the essence of the variability and expand that to file and log names:

for x in condition encounter procedure provider
do
. 
.
.
done

Can you please elaborate this pls?

The script runs, and i am able to get the attachment, but no data in the attachment.

condition-20101101.log (308 B), 
encounter-20101101.log (308 B), 
procedure-20101101.log (308 B), 
provider-20101101.log (308 B).

Funny, ugly but works fine for me (old hp); you must be close!

(echo 'Hello,
yack yack
Best,
David
'
uuencode .profile .profile ) | mailx -m -s uuencode2x my_email@my_host

Can you tell me as what's wrong with this script":

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 & PROVIDER LOAD PROCESS FINISHED SUCCESSFULLY."
(
for logfile in "${logfile1}" "${logfile2}" "${logfile3}" "${logfile4}"
do
echo "CONDITION:" $( wc -l < /space/dbexport/PHR/data/conditionExport_test.csv),
echo "ENCOUNTER:" $( wc -l < /space/dbexport/PHR/data/encounterExport.csv),
echo "PROCEDURE:" $( wc -l < /space/dbexport/PHR/data/procedureExport.csv),
echo "PROVIDER:" $( wc -l < /space/dbexport/PHR/data/providerExport.csv);
done
for logfile in "${logfile1}" "${logfile2}" "${logfile3}" "${logfile4}"
do
attachment=`basename "${logfile}"`
"${logfile}" | uuencode "${attachment}"
echo ""
done
) | mailx -m -s "${subject}" "$to" id11355@gmail.com

1) I am able to get the log file as attachement,, but the file has no data..
2) I am getting the output as:

CONDITION: 2000
ENCOUNTER: 1000
PROCEDURE: 1000
PROVIDER: 150
CONDITION: 2000
ENCOUNTER: 1000
PROCEDURE: 1000
PROVIDER: 150
CONDITION: 2000
ENCOUNTER: 1000
PROCEDURE: 1000
PROVIDER: 150
CONDITION: 2000
ENCOUNTER: 1000
PROCEDURE: 1000
PROVIDER: 150

Required output should be:

CONDITION: 2000
ENCOUNTER: 1000
PROCEDURE: 1000
PROVIDER: 150