1834137 Members
2312 Online
110064 Solutions
New Discussion

Monitoring Script

 
SOLVED
Go to solution
FrankBurg
Occasional Advisor

Monitoring Script

Hi Experts. I am new in scripting. I need to make a script to monitoring the percent
(%) of cpu usage in hp-ux machines...In the same way a script to monitoring the memory usage (%)...Please can you help me...
Thanks...
5 REPLIES 5
IT_2007
Honored Contributor

Re: Monitoring Script

Please explain cleary meaning of monitoring. Do you want to capture CPU and Memory usage during certain period or capture data and recompile it later?

Glance and top commands will help you to monitor system activity.
FrankBurg
Occasional Advisor

Re: Monitoring Script

Hi IT_2007, I don't want to collect the information about cpu or memory usage in a period of time. I need a snapshot to determine which is the process (only one) using more cpu or memory...and then kill it.
spex
Honored Contributor

Re: Monitoring Script

Hi Frank,

pid of process consuming most CPU displayed on stdout:
# UNIX95= ps -e -o "pcpu,pid" | sort -n -k1 | tail -1 | awk '{print $2}'

pid of process consuming most memory displayed on stdout:
# UNIX95= ps -e -o "vsz,pid" | sort -n -k1 | tail -1 | awk '{print $2}'

PCS
FrankBurg
Occasional Advisor

Re: Monitoring Script

Thanks spex, I understand the pipe commnad, but, tell me something, why are you using the variable UNIX95?...I don't understand that...
spex
Honored Contributor
Solution

Re: Monitoring Script

Hi Frank,

Setting UNIX95 enables XPG4 behavior for a command, which typically adds extra functionality. In the case of 'ps', XPG4 behavior allows extra columns to be specified. Remember to never export UNIX95 to your environment, as it will cause unexpected behavior in certain commands.

PCS