Operating System - HP-UX
1755605 Members
5015 Online
108836 Solutions
New Discussion юеВ

massaging an output file into a readable format.

 
SOLVED
Go to solution
fg_1
Trusted Contributor

massaging an output file into a readable format.

All

I am running a script that has an output file which when generated list all my backups, this part of it all works the way I want it to.

The problem I have with the attached file is 2 fold:
1) I want to massage the file into neat readable collumns.
2) I want to wrap the file in HTML and then email it out.

Can any of you help me here. I am listing the script here and attaching the output file.

Thanks in advance.

FG
#!/usr/bin/ksh -v
#
# This script is being developed to provide a detailed report of the previous day's backup
# jobs from netbackup. This script will be executed daily at 10:00AM.
# Upon successful completion, the output from this script will be webified using html and then
# emailed to the it_backup_admins mailing list.
#
# This script must be executed utlizing the root user account.

# Environmental section

set -u

BASEDIR=/home/fgrosb01
DATE=`date +%Y%m%d`
SCRIPT_REVISION="HPUX-b.11.00.01"
SCRIPT_HPUX_VERSION=$(uname -r)
SCRIPT_SYSTEM=$(uname - n)
SCRIPT_USER=$(whoami)
SCRIPT_EXECUTION_TIME=$(date +'%Y/%m/%d/%H:%M:%S')
MAIL=/usr/bin/mailx
ADDRESS="frank.grosberger@chsli.org"
INPUT_FILE=${BASEDIR}/${DATE}.fullnbujobsreport
OUTPUT_FILE=${BASEDIR}/${DATE}.nbujobsreport

echo ${SCRIPT_SYSTEM} \(Version ${SCRIPT_REVISION}\) ${SCRIPT_EXECUTION_TIME}
echo _____________________________________________________________________
echo

if [ ${SCRIPT_USER} != "root" ] ; then
echo
echo "This program must be executed utilizing the root logon id only"
echo
return 501
fi
echo _______________________________________________________________________
###########################################################################
#
# This section of the script will execute the bpdbjobs command utilizing
# the file /home/fgrosb01/.xbpmonrcfg as it's configuration file for the
# output.

bpdbjobs -header -report -format ${BASEDIR}/.xbpmonrcfg > ${INPUT_FILE}

cat ${INPUT_FILE} | awk '{
jobid=substr($0,1,10);
jobtype=substr($0,12,11);
jobstate=substr($0,24,8);
status=substr($0,33,8);
class=substr($0,42,27);
schedule=substr($0,70,18);
client=substr($0,89,26);
mediaserver=substr($0,116,26);
started=substr($0,143,21);
elapsed=substr($0,165,14);
ended=substr($0,180,21)
Kbytes=substr($0,202,13);
files=substr($0,216,13);
compestimated=substr($0,230,11);
printf("%s%s%s%s%s%s%s%s%s%s%s\n",jobid,jobtype,client,class,schedule,
server,started,ended,Kbytes,files,compestimated);
}' > ${OUTPUT_FILE}

cat ${OUTPUT_FILE} | $MAIL -s "Netbackup Jobs Report ${SCRIPT_EXECUTION_TIME}" $ADDRESS
exit 0
3 REPLIES 3
Rodney Hills
Honored Contributor
Solution

Re: massaging an output file into a readable format.

You could embed the necessary html code as part of the output file.

Here is your awk script with html inserted.

cat ${INPUT_FILE} | awk '{
BEGIN{
print "Backup List";
print "";
print "

\n";
print "...repeat for each title";
};
jobid=substr($0,1,10);
jobtype=substr($0,12,11);
jobstate=substr($0,24,8);
status=substr($0,33,8);
class=substr($0,42,27);
schedule=substr($0,70,18);
client=substr($0,89,26);
mediaserver=substr($0,116,26);
started=substr($0,143,21);
elapsed=substr($0,165,14);
ended=substr($0,180,21)
Kbytes=substr($0,202,13);
files=substr($0,216,13);
compestimated=substr($0,230,11);
printf("\n",jobid,jobtype,client,class,schedule,
server,started,ended,Kbytes,files,compestimated);
};
END{
print "
Title Field1Title Field2%sa%s%s%s%s%s%s%s%s%s%s
";
print ""
' > ${OUTPUT_FILE}


hope this helps...

-- Rod Hills

There be dragons...
Sridhar Bhaskarla
Honored Contributor

Re: massaging an output file into a readable format.

Hi Frank,

I am not sure if I understood your requirement. Your output does seem readable. If you want to strip out some of the columns, you can easily do it using awk. Job id is column 1, job type is column 2, clinet col 3 etc., If you want to print only Job id, Client, Schedule, Start time (col 6 and 7) and End time (col 8 and 9), then you would keep an awk statement as below.


.......
bpdbjobs -header -report -format ${BASEDIR}/.xbpmonrcfg > ${INPUT_FILE}



cat ${INPUT_FILE} |awk '{print $1,$3, $5,$6, $7, $8, $9}' >> ${OUTPUT_FILE}

#Put it in html format

cat << EOF >> ${OUTPUT_FILE}.html



EOF
cat ${OUTPUT_FILE} |while read LINE
do
echo "" >> ${OUTPUT_FILE}.html
for TD in $LINE
do
printf "" $TD >> ${OUTPUT_FILE}.html
done
printf "\n" >> ${OUTPUT_FILE}.html

echo "" >> ${OUTPUT_FILE}.html
done
cat << EOF >> ${OUTPUT_FILE}.html
%s



EOF

.......


If you want more columns, you can add the corresponding column number to $variable in the first awk column.

I hope this helps you,

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: massaging an output file into a readable format.

Hi (again),

Forgot to clarify. ${OUTPUT_FILE} is the simple ascii output and ${OUTPUT_FILE).html is the html output. You can add the other lines of script to it like add additional headers, send mail etc.,

-Sri
You may be disappointed if you fail, but you are doomed if you don't try