Performance problem with my script ...suggestions pls


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Performance problem with my script ...suggestions pls
# 1  
Old 02-22-2008
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 05:06 PM.. Reason: corrections
# 2  
Old 02-22-2008
quick answer - use the "sleep" command to make your process go dormant for a set amount of time.

do a man sleep - but basically, the command is sleep <seconds>
# 3  
Old 02-23-2008
My first thought was using sleep, too, but he is.

Code:
sleep 600

So, maybe that long of a sleep is giving the CPU fits? when I had this problem before, and wasn't using a sleep command, I solved it using sleep 1 which gave the CPU plenty of time to catch up on other things.

I can't imagine a company setting a policy against using one of the most powerful friends a sysadmin has. Amazing what people do.... But, I've an open mind. Convince me that prohibiting the use of cron is a good idea.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance problem in Shell Script

Hi, I am Shell script beginner. I wrote a shell programming that will take each line of a file1 and search for it in another file2 and give me the output of the lines that do not exist in the file2. I wrote it using do while nested loop but the problem here is its running for ever . Is there... (12 Replies)
Discussion started by: sakthisivi
12 Replies

2. Shell Programming and Scripting

Suggestions on this script please

i=1 out="" j=`expr 2 * $1` while do out="$out"#"" echo $out ((i=i+1)) done while do print ${out%?} ((i=i+1)) done This script is throwing an error: gurnish:/home/fnb/gurnish/saurabh/scripts> while1 3 expr: 0402-050 Syntax error. # (6 Replies)
Discussion started by: targetshell
6 Replies

3. Linux

Creating .iso from DVD problem ( looking for alternatives / suggestions )

I want to be able to copy DVD disks directly to an ISO file from the command line (via bash script). I have such a script that I have refined over time that works quite well about 80% of the time. About two DVD's out of ten will not burn to an iso file, and the script hangs on one of the... (4 Replies)
Discussion started by: jvsrvcs
4 Replies

4. Shell Programming and Scripting

Problem.. can someone pls help..

Hi All, My file contains data like below. Key ~PILCSZY First Name Szymon Surname Pilch User Code Group SCO-PL User Group Description SCO - Poland Key ... (2 Replies)
Discussion started by: harshakusam
2 Replies

5. Shell Programming and Scripting

Script Performance problem . urgent frnds

HI frnds I have one flat with data and am loading the data into oracle table. While loading , rejected records are captured in log file. Now I want to read the log file and get the all rejected records and the reason for the rejection. I developed the script . its finding 5000 rejected... (7 Replies)
Discussion started by: Gopal_Engg
7 Replies

6. Shell Programming and Scripting

Simple program but problem-pls Help

Hi All, I have problem in the following shell script (problem in 2and3 line i guess) #!/bin/sh set value1 = 90; set value2 = 70; if ; then echo "$value1 is normal" else echo "$value2 is abnormal" fi when executed output: $ value_test.sh (Enter) is abnormal Neither it's printing... (13 Replies)
Discussion started by: user__user3110
13 Replies

7. Shell Programming and Scripting

Need suggestions about a datecheck script

I'm currently running a script that checks to see if a laptop is on the network, and if it is it backs up, if not it retries it later. Anyway, our backup scheduling has changed. I need to check if today's date is the Thursday after the first Wednesday of every month. This is made slightly more... (5 Replies)
Discussion started by: tsmurray
5 Replies

8. UNIX for Dummies Questions & Answers

Bash: bad substitution problem...pls help!

I have this situation in my script (simplified): A=C C=10 I need to get number 10 using just A variable. I tried with : echo $`echo $A` - but i get $C string (i need number) Thanks very much for any help! (1 Reply)
Discussion started by: xfouxs
1 Replies

9. UNIX for Advanced & Expert Users

suggestions require for unix system performance on certain task

Dear all, On my UNIX server there is an apache web log file. The rate of logging of data in this file is very high. I want to extract user logging log from this file in run time. As soon as the user logging log logged in this file I want to redirect this user log into another file. I want to... (4 Replies)
Discussion started by: zing_foru
4 Replies

10. Shell Programming and Scripting

Problem with Tail command --urgent pls

eg: If I execute an example tail statement to put rows from one file to another, it truncates some of the data. /carrier>wc -l IntIndA.txt 1918 IntIndA.txt /carrier>tail -1918 IntIndA.txt > test /carrier>wc -l test 132 test The tail command should copy 1918 rows to test file instead of... (4 Replies)
Discussion started by: subbukns
4 Replies
Login or Register to Ask a Question