02-22-2008
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
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
2. UNIX for Advanced & Expert Users
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
3. UNIX for Dummies Questions & Answers
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
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
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
6. Shell Programming and Scripting
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
7. Shell Programming and Scripting
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
8. Linux
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
9. Shell Programming and Scripting
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
10. Shell Programming and Scripting
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
LEARN ABOUT OPENDARWIN
ptree
ptree(1) ptree(1)
NAME
ptree - print process trees
SYNOPSIS
/usr/bin/ptree [-a] [-c] [-z zone] [pid | user] ...
ptree prints the process trees containing the specified pids or users, with child processes indented from their respective parent pro-
cesses. An argument of all digits is taken to be a process-id, otherwise it is assumed to be a user login name. The default is all pro-
cesses.
The following options are supported:
-a All. Print all processes, including children of process 0.
-c Contracts. Print process contract memberships in addition to parent-child relationships. See process(4). This option
implies the -a option.
-z zone Zones. Print only processes in the specified zone. Each zone ID can be specified as either a zone name or a numerical zone
ID.
This option is only useful when executed in the global zone.
The following operands are supported:
pid Process-id or a list of process-ids. ptree also accepts /proc/nnn as a process-id, so the shell expansion /proc/* can be
used to specify all processes in the system.
user Username or list of usernames. Processes whose effective user IDs match those given are displayed.
Example 1: Using ptree
The following example prints the process tree (including children of process 0) for processes which match the command name ssh:
$ ptree -a `pgrep ssh`
1 /sbin/init
100909 /usr/lib/ssh/sshd
569150 /usr/lib/ssh/sshd
569157 /usr/lib/ssh/sshd
569159 -ksh
569171 bash
569173 /bin/ksh
569193 bash
The following exit values are returned:
0 Successful operation.
non-zero An error has occurred.
/proc/* process files
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWesu |
+-----------------------------+-----------------------------+
|Interface Stability |See below. |
+-----------------------------+-----------------------------+
The human readable output is Unstable. The options are Evolving.
gcore(1), ldd(1), pargs(1), pgrep(1), pkill(1), plimit(1), pmap(1), preap(1), proc(1), ps(1), ppgsz(1), pwd(1), rlogin(1), time(1),
truss(1), wait(1), fcntl(2), fstat(2), setuid(2), dlopen(3C), signal.h(3HEAD), core(4), proc(4), process(4), attributes(5), zones(5)
11 Oct 2005 ptree(1)