Memory check script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Memory check script
# 1  
Old 09-30-2010
Memory check script

Hi all,

OS: Solaris 10

I'm trying to put together a script to check memory utilisation.

The command I'm running is:

ps -ef -o pmem -o pid -o rss -o vsz -o args -o user | grep 2 | grep -v "VSZ COMMAND" | sort | tail -10 | sort -r

And the output looks something like this:

==============================
2.4 1103 761936 1357176 PSAPPSRV -C dom=FSPRD5_56906 -g 99 -i 8 -u syd0738 -U /psoft/fs/fsprd/psft/pt/8 fsprd
2.0 4744 636944 758368 JSH -c 41 -i 5 -s 96 -S 1320 fsprd
1.7 27412 540088 1119624 PSAPPSRV -C dom=FSPRD3_38073 -g 99 -i 6 -u syd0738 -U /psoft/fs/fsprd/psft/pt/8 fsprd
1.7 4617 539912 965504 PSSUBHND -C dom=FSPRDIB_65215 -g 98 -i 302 -u syd0738 -U /psoft/fs/fsprd/psft/p fsprd
1.6 29539 498288 536760 PSAPPSRV -C dom=FSPRD5_56906 -g 99 -i 1 -u syd0738 -U /psoft/fs/fsprd/psft/pt/8 fsprd
1.6 29282 498096 536752 PSAPPSRV -C dom=FSPRD5_56906 -g 99 -i 7 -u syd0738 -U /psoft/fs/fsprd/psft/pt/8 fsprd
1.6 25877 525032 1103712 PSAPPSRV -C dom=FSPRD5_56906 -g 99 -i 9 -u syd0738 -U /psoft/fs/fsprd/psft/pt/8 fsprd
1.6 6227 497384 528568 PSAPPSRV -C dom=FSPRD1_38536 -g 99 -i 2 -u syd0738 -U /psoft/fs/fsprd/psft/pt/8 fsprd
1.6 4614 514544 932736 PSSUBHND -C dom=FSPRDIB_65215 -g 98 -i 301 -u syd0738 -U /psoft/fs/fsprd/psft/p fsprd
1.5 5798 469792 512208 PSQRYSRV -C dom=FSPRD3_38073 -g 99 -i 72 -u syd0738 -U /psoft/fs/fsprd/psft/pt/ fsprd
==============================

What I know to know is what command I can use so that if the first column is greater than 3.0 i.e. -gt 3.0 (which represents % memory usage), then satisfy a condition.

Looking forward to hearing some suggestions. Something written for korn shell would be perfect.

Thanks in advance.

Last edited by d-train; 09-30-2010 at 09:42 PM.. Reason: Edited command
# 2  
Old 09-30-2010
Assuming you are running Kshell you could pipe it into a while like this:

Code:

ps -ef -o pmem -o pid -o rss -o vsz -o args -o user | grep 2 | grep -v "VSZ COMMAND" | sort | tail -10 | sort -r | while read used rest
do
     if (( $used > 3.0 ))
     then
         echo "$rest"
     fi
done

Bash throws an error when I attempt something like this, so you'll probably have to do something like the following if you must use bash:

Code:

ps -ef -o pmem -o pid -o rss -o vsz -o args -o user | grep 2 | grep -v "VSZ COMMAND" | sort | tail -10 | sort -r | while read used rest
do
     if (( ${used/./} > 30 ))       # replace . with nil and compare to threshold * 10
     then
         echo "$rest"
     fi
done

This User Gave Thanks to agama For This Post:
# 3  
Old 09-30-2010
Thanks agama. I'm using Korn so gave the first solution a try but it did not work:

Code:
#!/bin/ksh -x
ps -ef -o pmem -o pid -o rss -o vsz -o args -o user | grep 2 | grep -v "VSZ COMMAND" | sort | tail -10 | sort -r | while read used rest
do
     if (( $used > 3.0 ))
     then
         echo "$rest"
     fi
done

The result of the above script is:

syd0738:fsprd:/tmp> ./dt.sh
+ grep 2
+ ps -ef -o pmem -o pid -o rss -o vsz -o args -o user
+ grep -v VSZ COMMAND
+ read used rest
+ tail -10
+ sort
+ sort -r
+ (( 2.4 > 3.0 ))
+ read used rest
+ (( 2.0 > 3.0 ))
+ read used rest
+ (( 1.7 > 3.0 ))
+ read used rest
+ (( 1.7 > 3.0 ))
+ read used rest
+ (( 1.6 > 3.0 ))
+ read used rest
+ (( 1.6 > 3.0 ))
+ read used rest
+ (( 1.6 > 3.0 ))
+ read used rest
+ (( 1.6 > 3.0 ))
+ read used rest
+ (( 1.5 > 3.0 ))
+ read used rest
+ (( 1.5 > 3.0 ))
+ read used rest

Any clues?
# 4  
Old 09-30-2010
Looks to me like none of your values are greater than 3.0, so nothing is being printed. Test by setting 3.0 to 1.5 or somesuch and see if there is a difference.
# 5  
Old 09-30-2010
Alright. It looks like it doesn't take into account the percentage point.

For example, I tried with ">1.0", and the only row that echoed was a result that was "2.0".

Rows of for example "1.6, 1.7" did not echo.

This is not a big deal as I'm happy to be notified with any results of 3 and above.

Let me play around with the command and will let you know how I go.

Cheers.
# 6  
Old 10-01-2010
Update from your own code.

Code:
ps -ef -o pmem -o pid -o rss -o vsz -o args -o user |awk '!/VSZ COMMAND/&&/2/&&$1>3.0' |sort -r |head -10

This User Gave Thanks to rdcwayx For This Post:
# 7  
Old 10-01-2010
Thanks agama and rdcwayx.

Both your solutions worked a treat.

Cheers guys.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Memory Usage check

Hello Friends, I need to check memory usage & availability before I could run a program if there is enough memory is left or not, so how could i achieve this? Which command output i should rely on? I have diplayed outputs of SAR, VMstat and PRstat commands below, But how could i check memory... (8 Replies)
Discussion started by: EAGL€
8 Replies

2. AIX

Script to check the memory usage in AIX

Hello Everyone, I'm looking for a efficient script that monitors the memory usage on AIX and send email alerts when it reaches certain point. Q) need to get alerts, when the memory usage exceed 90% on AIX? or Q) Need to get alerts when available free Memory is 1G or 10% etc Any idea... (3 Replies)
Discussion started by: System Admin 77
3 Replies

3. Linux

how to check memory usage ?

hello, I have purchased VPS from one webhosting company. VPS comes with Virtuozzo power panel. It has 512MB gurranted RAM and dynamic RAM 2048 MB. I have hosted single domain with 50MB database and wordpress installation. But I am getting resource alerts. It goes sometime in yellow... (8 Replies)
Discussion started by: mrugesh78
8 Replies

4. SuSE

How to check Memory Utilization by each process

If following is the usage of cat /proc/meminfo MemTotal: 4051304 kB MemFree: 28544 kB Buffers: 216848 kB Cached: 3398628 kB SwapCached: 0 kB Active: 455460 kB Inactive: 3291612 kB HighTotal: 0 kB HighFree: 0 kB... (5 Replies)
Discussion started by: bryanabhay
5 Replies

5. UNIX for Advanced & Expert Users

Check memory leak

I am running c++ code on AIX unix.I have a doubt that my code is using some memory but it is not clearing that.Some time i am getting heap allocation problem.In my code i am not using any malloc,new functions also i am justing using pointers and arrays. Is there any way i can find out if the... (2 Replies)
Discussion started by: ukatru
2 Replies

6. Solaris

Command to check memory size

Hi, I am looking for acoomand on HP where by i can see the CPU increasing for a given process ... I know i can see this from top/prstat .. But it will give for all the processes - I want something like say ps where i can call it from a shell script a few times and check if it is has increased... (0 Replies)
Discussion started by: nano2
0 Replies

7. UNIX for Dummies Questions & Answers

check memory and processors

HI , I have AIX 5.2 ? I believe. I am looking to see how many processors I have and what the Memory is in this box? I know there is a command to run but I am really rusty at this Thanks Dave (2 Replies)
Discussion started by: rocker40
2 Replies

8. Solaris

How to check physical memory

HI Please help me how to check the physical memory, model name and hardisk information. (5 Replies)
Discussion started by: jeelans
5 Replies

9. Programming

how to use ioctl to check out memory usage

Hi all, I tried to output memory usage information while the process is executing at a particular time. I found out some people suggesting calling the ioctl. I followed it and wrote a test example: #include <unistd.h> #include <stdlib.h> #include <iostream.h> #include <fcntl.h> #include... (2 Replies)
Discussion started by: lanchen
2 Replies

10. UNIX for Dummies Questions & Answers

how to check how much memory being used?

is there other way to check how much physical memory being used without using top command?....this is on Sun Solrais 2.7 (3 Replies)
Discussion started by: dookeobih
3 Replies
Login or Register to Ask a Question