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?
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
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!
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 .
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:
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.
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.
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
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