Operating System - HP-UX
1834431 Members
2312 Online
110067 Solutions
New Discussion

Need some help with coding output.

 
SOLVED
Go to solution
fg_1
Trusted Contributor

Need some help with coding output.

Hello all.

1) I am trying to figure out the error at the bottom of this output from my script, I have coded some html in there too and i am wondering if that's the problem. Any ideas here would be good.

2) I was also wondering with the way I am doing the grep at the bottom for todays date and yesterdays date if that will work in the way its listed.

I am also attaching the script here for reviewing purposes.

mmdcux17@/home/fgrosb01# ./bpdbjobs.output
#!/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`
YDATE=`expr $DATE - 1`
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
TMP_FILE=${BASEDIR}/${DATE}.tmpnbujobsreport
OUTPUT_FILE=${BASEDIR}/${DATE}.nbujobsreport

echo ${SCRIPT_SYSTEM} \(Version ${SCRIPT_REVISION}\) ${SCRIPT_EXECUTION_TIME}
HP-UX (Version HPUX-b.11.00.01) 2002/08/21/10:58:36
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 '{
BEGIN{
print "Netbackup Daily Report for ${DATE}";
print "";
print "

\n";
print "server,status,started,ended,Kbytes,files,compestimated);
};
END{
print "
jobidjobtypeclientclassscheduleserverstatusstarted};
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
";
print ""
' >${TMP_FILE}
syntax error The source line is 2.
The error context is
>>> BEGIN <<< {
awk: The statement cannot be correctly parsed.
The source line is 2.
syntax error The source line is 21.
awk: There is a missing } character.

cat ${TMP_FILE} | grep -e ${DATE} -e ${YDATE} > ${OUTPUT_FILE}

cat ${OUTPUT_FILE} | $MAIL -s "Netbackup Jobs Report ${SCRIPT_EXECUTION_TIME}" $ADDRESS
Null message body; hope that's ok
exit 0
mmdcux17@/home/fgrosb01#

4 REPLIES 4
Rodney Hills
Honored Contributor
Solution

Re: Need some help with coding output.

Misplaced "{"

cat ${INPUT_FILE} | awk '{
BEGIN{
print "Netbackup Daily Report for ${DATE}";
print "";
print "

\n";
print "
jobidjobtypeclientclassscheduleserverstatusstarted};
jobid=substr($0,1,10);


should be-

cat ${INPUT_FILE} | awk 'BEGIN{
print "Netbackup Daily Report for ${DATE}";
print "";
print "

\n";
print "
jobidjobtypeclientclassscheduleserverstatusstarted};
{
jobid=substr($0,1,10);

Structure of awk file is-
BEGIN{ ... }
{ ...process for each line...}
END{ ... }

Hope this helps...

-- Rod Hills

There be dragons...
harry d brown jr
Honored Contributor

Re: Need some help with coding output.


You need to CLOSE your HTML

print ""

SHOULD be

print "";

AND

get rid of the FIRST {

in cat ${INPUT_FILE} | awk '{

SHOULD be

cat ${INPUT_FILE} | awk '

AND

BODY of awk should have the { to start it, as in

{jobid=substr($0,1,10);


live free or die
harry
Live Free or Die
fg_1
Trusted Contributor

Re: Need some help with coding output.

Thank you both for the assist, but now i seem to be missing something else. i have reattached the output again here.mmdcux17@/home/fgrosb01# ./bpdbjobs.output
#!/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`
YDATE=`expr $DATE - 1`
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
TMP_FILE=${BASEDIR}/${DATE}.tmpnbujobsreport
OUTPUT_FILE=${BASEDIR}/${DATE}.nbujobsreport

echo ${SCRIPT_SYSTEM} \(Version ${SCRIPT_REVISION}\) ${SCRIPT_EXECUTION_TIME}
HP-UX (Version HPUX-b.11.00.01) 2002/08/21/11:24:28
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 'BEGIN{
print "Netbackup Daily Report for ${DATE}";
print "";
print "

\n";
print "server,status,started,ended,Kbytes,files,compestimated);
};
END{
print "
jobidjobtypeclientclassscheduleserverstatusstarted};
{
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
";
print "";
' >${TMP_FILE}
syntax error The source line is 28.
The error context is
print ""; >>>
<<<
awk: The statement cannot be correctly parsed.
The source line is 28.
awk: There is a missing } character.

cat ${TMP_FILE} | grep -e ${DATE} -e ${YDATE} > ${OUTPUT_FILE}

cat ${OUTPUT_FILE} | $MAIL -s "Netbackup Jobs Report ${SCRIPT_EXECUTION_TIME}" $ADDRESS
Null message body; hope that's ok
exit 0
mmdcux17@/home/fgrosb01#


Rodney Hills
Honored Contributor

Re: Need some help with coding output.

The code-
END{
print "";
print "";
' >${TMP_FILE}

needs to be-
END{
print "";
print "";
}' >${TMP_FILE}

Additional "}" to close END.

If you use "vi" to edit this awk script, use can use "%" to help find matching "{" "}" together.

Recommend that you test each phase of the script separatelly. To verify the results of each filter get what you think you want.

My 2 cents.

-- Rod Hills
There be dragons...