Operating System - HP-UX
1833832 Members
2161 Online
110063 Solutions
New Discussion

A script help for cat top information

 
SOLVED
Go to solution
violin
Occasional Advisor

A script help for cat top information

Hello,

We want to monitor top info about every 5 mins.
in hp-ux, top command will give info like this:
System: gbm2 Tue May 7 11:09:21 2002
Load averages: 1.86, 1.99, 2.23
599 processes: 590 sleeping, 9 running
Cpu states:
CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS
0 2.10 73.2% 0.0% 10.4% 16.3% 0.0% 0.0% 0.0% 0.0%
1 1.92 69.1% 0.0% 12.6% 18.3% 0.0% 0.0% 0.0% 0.0%
2 1.45 60.4% 0.0% 13.6% 26.0% 0.0% 0.0% 0.0% 0.0%
3 1.98 75.6% 0.0% 5.5% 18.9% 0.0% 0.0% 0.0% 0.0%
--- ---- ----- ----- ----- ----- ----- ----- ----- -----
avg 1.86 69.7% 0.0% 10.4% 19.9% 0.0% 0.0% 0.0% 0.0%

Memory: 4234240K (1405072K) real, 3909564K (1203124K) virtual, 1066808K free Pa
ge# 1/67

CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU COMMAND
0 ? 25550 erpmgr 235 20 27240K 10960K run 0:07 19.26 19.23 f60webmx
2 ? 10798 erpmgr 148 20 48376K 34240K sleep 1:49 14.18 14.16 f60webmx
1 ? 25116 erpmgr 154 20 32504K 16600K sleep 0:13 9.06 9.05 f60webmx
0 ? 10638 oraerp 148 20 34596K 6144K sleep 0:52 8.96 8.95 oraclePR
2 ? 21403 erpmgr 154 20 33176K 17460K sleep 0:29 8.76 8.74 f60webmx
2 ? 13572 erpmgr 216 20 39560K 24264K run 2:59 8.24 8.22 f60webmx
2 pts/ta 25801 oraerp 154 20 1056K 2852K sleep 0:02 21.80 7.90 vi
1 ? 25252 erpmgr 154 20 28904K 13536K sleep 0:07 7.01 6.99 f60webm

Please help me how to print 1st , 11th and 13th lines,
like this:
System: gbm2 Tue May 7 11:09:21 2002
avg 1.86 69.7% 0.0% 10.4% 19.9% 0.0% 0.0% 0.0% 0.0%
Memory: 4234240K (1405072K) real, 3909564K (1203124K) virtual, 1066808K free Page# 1/67

Thanks again.

Violin.
9 REPLIES 9
Deepak Extross
Honored Contributor
Solution

Re: A script help for cat top information

Try this:
top -d 1 | egrep 'Memory|System'
Deepak Extross
Honored Contributor

Re: A script help for cat top information

And here's teh script to monitor it every 5 minutes:

while true
do
top -d 1 | egrep 'Memory|System'
sleep 10
clear
done
Deepak Extross
Honored Contributor

Re: A script help for cat top information

oops..missed out the "avg".
egrep 'Memory|System|avg'
Niraj Kumar Verma
Trusted Contributor

Re: A script help for cat top information

small script

#!/bin/sh

top -f /tmp/top.out
echo " ========================="
grep ^Memory /tmp/top.out
grep ^avg /tmp/top.out
echo " ============================"

# End


-Niraj
Niraj.Verma@philips.com
John McWilliams
Advisor

Re: A script help for cat top information

Another option would be to use the scripts above but use cron to call the script every 5 minutes.

Cheers John
violin
Occasional Advisor

Re: A script help for cat top information

Hello,

Thanks for your reply.

I try to edit a shell like this:

#!/bin/sh
while true
do
echo "-----------------------"
top -d 1 | egrep 'Memory|System|avg'
sleep 10
clear
done



And then try run and spool to log:
. top5 >> top5.log

But the top5.log is :

[?25h [m [H [J 7 [1;24r 8 [4lSystem: gbm2 [42CTue May 7 12:20:33 2002
avg 0.40 2.0% 0.0% 1.0% 97.0% 0.0% 0.0% 0.0% 0.0%
Memory: 3365496K (621808K) real, 3140932K (575240K) virtual, 1940580K free Page
[H [J-------------------------------------------------
[?25h [m [H [J 7 [1;24r 8 [4lSystem: gbm2 [42CTue May 7 12:20:44 2002
avg 0.37 23.0% 0.0% 19.0% 58.0% 0.0% 0.0% 0.0% 0.0%
Memory: 3365992K (560664K) real, 3142028K (506684K) virtual, 1940036K free Page


Can you teach me how to discard those marks?
[m,[H......

Thanks again.

Violin.


Niraj Kumar Verma
Trusted Contributor

Re: A script help for cat top information

Do a little modification in your script

#!/bin/sh
while true
do
echo "-----------------------"
top -f top.out
cat top.out |egrep '^Memory|^System|^avg'
sleep 10
clear
done


-Niraj
Niraj.Verma@philips.com
violin
Occasional Advisor

Re: A script help for cat top information

Thanks for Niraj,

your script really works,
but another question again,
IF I want to execute this script after boot,
how can I do for this?

Sorry I'm not so familiar with HP-UX.

Thanks again.

Violin.
Niraj Kumar Verma
Trusted Contributor

Re: A script help for cat top information

you need to have a startup script in

/sbin/init.d/*

and proper link to respective rc directory
.

-Niraj
Niraj.Verma@philips.com