The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-22-2008
vivsiv vivsiv is offline
Registered User
 

Join Date: Jun 2006
Location: Los Angeles
Posts: 17
Question Performance problem with my script ...suggestions pls

Hi ,
I have included my script below, pls read thro this req. I want my script to run for every hour , the problem is I CANNOT USE CRONTAB which is prohibited inside the company. My script does what it is supposed to do (to determine the memory and then send a email if it crosses a certain limit) . So I put a while loop which is always true so that the script can run forever using nohup but the problem is that this script if run using nohup and while true condition seem to REALLY take up almost 1 full cpu from the server (our server is a 3 cpu box) ..do u guys have any idea how to make this less CPU intensive one..??
_____ Script ----
#!/bin/ksh
set -A proc $x
x=$(top| grep sieb |awk '{print $6}'|sed 's/\M//')
print $x
HOME=/users/home/con
TEMPDIR=$HOME
FILE=mail.log
set -A proc $x
print "Number of sieb process currently running is ${#proc[@]}"
#assigning the total number of processes to a var
procnum=${#proc[@]}
print ${proc[1]}
#to make the script run contineous im putting a while [true]
while [ true ]
do
#intializing a counter var to be in loop
i=0
while [ $i -lt $procnum ]
do
echo 'Start checking '
if [ ${proc[i]} -gt 1420 ]
then
echo Process Sieb seem to occupy more memory about ${proc[i]} MB so will sleep for 10mins before i do next check
sleep 600
typically 62% means the overall emory is 83%
cp=$(prstat -t 1 1 | awk '/sad/{print $5;}'|sed 's/\%//')
echo $cp is the % MEM
if [ ${proc[i]} -gt 1420 ] && [ $cp -gt 61 ]
then
echo Sieb seem to occupy more memory so will send a email
/usr/bin/mailx -s "ALERT: process memory on rog is high " "con@yahoo.com" < $TEMPDIR/$FILE
sleep 3600
fi
fi
print ${#proc[$i]}
((i=i+1))
echo $i
done
done

Last edited by vivsiv; 02-22-2008 at 01:06 PM. Reason: corrections
Reply With Quote
Forum Sponsor