Operating System - HP-UX
1764041 Members
3075 Online
108921 Solutions
New Discussion юеВ

Problem with expression within ksh script.

 
SOLVED
Go to solution
fg_1
Trusted Contributor

Problem with expression within ksh script.

Hello all

I have been beating myself against the wall with this script of mine for several days. I feel as though i am in the home stretch but I need some help on a few things with it.

1) It seems as though the YDATE variable near the top of the script is not functioning at all by the error i am getting from the expr, any clues there. I have to leave the DATE variable in the current format to match the date fields in my output file.

2) It also seems as though my HTML is not producing a line by line report but more rather a one line report all the way across the screen. If you take the output file attached here and open it with IE you will see what i am having as output. I need to make it so it reports each line as a new line on the report.

TY in advance.
fg.




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 +%m/%d/%Y`
FDATE=`date +%m%d%Y`
YDATE=`expr $DATE - 1`
expr: An integer value was expected.

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}/${FDATE}.fullnbujobsreport
TMP_FILE=${BASEDIR}/${FDATE}.tmpnbujobsreport
OUTPUT_FILE=${BASEDIR}/${FDATE}.nbujobsreport

echo $SCRIPT_SYSTEM \(Version $SCRIPT_REVISION\) $SCRIPT_EXECUTION_TIME
HP-UX (Version HPUX-b.11.00.01) 2002/08/21/15:45:30
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}

grep -i ${DATE} ${TMP_FILE} > ${OUTPUT_FILE}
grep -i ${YDATE} ${TMP_FILE} >> ${OUTPUT_FILE}

cat ${OUTPUT_FILE} | $MAIL -s "Netbackup Jobs Report ${SCRIPT_EXECUTION_TIME}" $ADDRESS


12 REPLIES 12
Rodney Hills
Honored Contributor
Solution

Re: Problem with expression within ksh script.

Since $DATE is in the format MM/DD/YY, then you can't use it in any calculations.

DATE=`date +%m/%d/%Y`
YDATE=`expr $DATE - 1`

If you want to compute yesterdays date, then
look into a routine called "caljd.sh". It is a handy script for doing date computations.

Do a search within the forum and you should be able to find it.

Good Luck.

-- Rod Hills
There be dragons...
Tom Maloy
Respected Contributor

Re: Problem with expression within ksh script.

You will need a different solution for YDATE. expr does integer arithmetic, not date arithmetic. So expr does not know how to do:

08/21/2002 - 1

Any chance you can use the caljd.sh script?

Carpe diem!
A. Clay Stephenson
Acclaimed Contributor

Re: Problem with expression within ksh script.

I'll address your YDATE problem.

Let's say that DATE = "08/20/2002". Just what is "08/20/2002" - 1? I suupose that you really want yesterday's date in that format.

Look for a thread "Yesterday's Date" that was posted yesterday and today in this Forum.
The basic idea is this
YDATE=$(caljd.sh -S "/") $(caljd.sh -p 1))


Invoke caljd.sh -u for a full usage.

You can find caljd.sh in the mentioned thread.
If it ain't broke, I can fix that.
Tom Maloy
Respected Contributor

Re: Problem with expression within ksh script.

For the HTML, could you put a couple of




in the tables?
Carpe diem!
A. Clay Stephenson
Acclaimed Contributor

Re: Problem with expression within ksh script.

Oops, I meant
YDATE=$(caljd.sh -S "/" $(caljd.sh -p 1))





If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Problem with expression within ksh script.

I may be blind but I can't find your tag.
If it ain't broke, I can fix that.
Rodney Hills
Honored Contributor

Re: Problem with expression within ksh script.

Frank,

For HTML code, their has to be a balance of tags. Here is a sample template showing the tags with their corresponding end-tags.


__
____Your Title here
__
__
____
______...
______...
______...
____
......
......

__



Ignore the "_", I had those in for indentation purposes only. As you can see has a at the end, has a
at the third line from the bottom. Make sure your code follows the structure for it do display correctly. You may want to check out-

http://freespace.virgin.net/sizzling.jalfrezi/iniframe.htm

For help with using HTML codes.

Good Luck

-- Rod Hills
There be dragons...
harry d brown jr
Honored Contributor

Re: Problem with expression within ksh script.


Frank,

Sorry, but I don't see an attachment???? Is it there? I have mozilla 1.1 and IE 6+ and neither see it.



In the BEGIN paragraph, the line:

print "jobidjobtypeclientclassscheduleserverstatusstarted
needs to have ;

The date stuff I think the others have nailed.

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: Problem with expression within ksh script.

some of those long lines are being truncated by the forum server.

Can you post the script as an attachment?? Maybe in another thread???

live free or die
harry
Live Free or Die