Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with simple script 1

Status
Not open for further replies.

netman4u

Technical User
Mar 16, 2005
176
US
Hello all,

I am trying to get a script to work that I did not write. It looks like it should be working:

Code:
#________________________________________________________________________
# Program: CPU3_check
#
# This script checks the CPU utilization of a system against
# a predetermined threshold. If the threshold is exceeded an
# email or a page is sent.
#
#
# Files used:
#	CPU3_threshold  = contains nodename and an integer threshold value (ex "40")
#	CPU3_report     = config file for extract to get GBL_CPU_TOTAL_UTIL
#	CPU3_notify     = list of people to email or page 
#	node.CPU3.ctime = contains output from extract utility
#________________________________________________________________________

OS=`uname -s`
echo "$OS"
if [[ $OS = AIX ]]
then
	EXT_DIR="/usr/lpp/perf/bin"
	MON_DIR="/var/opt/OV/bin/instrumentation
else
	EXT_DIR="/opt/perf/bin"
	MON_DIR="/var/opt/OV/bin/instrumentation
fi

#MON_DIR="/home/mt37810"

node=`uname -n`
ctime=`date +%y%m%d%H%M%S`
mtime=`date +%H`:00
outfile="/tmp/$node.CPU3.$ctime"
reportfile="$MON_DIR/CPU3_report"
notifyfile="$MON_DIR/CPU3_notify"

start_time="today-1"

#echo "start_time=$start_time"
#echo "mtime=$mtime"

if [ -f $MON_DIR/CPU3_threshold ]
then
	threshold=`cat $MON_DIR/CPU3_threshold | grep $node | awk '{ print $2 }'`
else
	threshold=60
fi

echo "Extract DIR = $EXT_DIR" 

$EXT_DIR/extract -xp -r $reportfile -f $outfile -b $start_time -e LAST -G

if [ -s $outfile ]
then
	CPU_util=`tail -1 $outfile`
else
	echo "CPU_util is null"
	exit 1
fi

#echo "CPU_util=$CPU_util"

# CPU utilization is a decimal number. Need to change to integer
int1=`echo $CPU_util | awk -F. '{ print $1 }'`
int2=`echo $CPU_util | awk -F. '{ print $2 }'`
if [ $int2 > 50 ] #round up if over 50
then
	CPU_util=`expr $int1 + 1`
else
	CPU_util=$int1
fi

#echo "CPU_util=$CPU_util"

if [ $CPU_util -ge $threshold ]
then
	message="$node CPU utilization is at $CPU_util% which is at or above the threshold of $threshold%"
#	echo "$message"
else
#	echo "CPU OK"
#	message="CPU OK"
	rm $outfile
	exit 0	
fi

while read notify_user 
do

#echo "notify_user=$notify_user."

	if [ `echo $notify_user | grep myairmail` ]
	then
		echo "$message" | mailx -m  $notify_user
		#echo "paging"
	else
		echo "$message" | mailx -s $node $notify_user
		#echo "emailing"
	fi
done < $MON_DIR/CPU3_notify

rm $outfile
exit 0

I'm running this on a sun server. It seems like the first "if" loop is not working. The line:

echo $OS

returns SunOS, however the line:

echo "Extract DIR = $EXT_DIR"

returns:

Extract DIR =

So the $EXT_DIR variable is not being set.

Also there is no shebang line, is that OK? I do mostly perl programming.

Any help is appreciated.


If at first you don't succeed, don't try skydiving.
 
Thanks for the reply, but I am getting the same thing.

If at first you don't succeed, don't try skydiving.
 
Don't have a server right now, so can't try it, but I'd try inserting EXT_DIR= before the first if then statement.
Something like:
Code:
...
OS=`uname -s`
echo "$OS"
EXT_DIR=
if [[ $OS = AIX ]]
then
    EXT_DIR="/usr/lpp/perf/bin"
    MON_DIR="/var/opt/OV/bin/instrumentation
else
    EXT_DIR="/opt/perf/bin"
    MON_DIR="/var/opt/OV/bin/instrumentation
fi
...

I always do that, but don't know if it's only because of java programing habits.
 
You are missing 2 "'s on the end of line that sets MON_DIR, which is doing whacky things with the variables. That is lines 21 and 24.

eugene
 
<slaps self on head> That was it! How did I miss that!

Thanks elgra. Star for you!

If at first you don't succeed, don't try skydiving.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top