Operating System - HP-UX
1748011 Members
3477 Online
108757 Solutions
New Discussion юеВ

Re: Script to capture cpu and memory utilization every hour

 
SOLVED
Go to solution
mohdamir
Frequent Advisor

Script to capture cpu and memory utilization every hour

Hi guys,
Really need your help to write a script so that I can capture cpu and memory utilization every hour.

TQ
6 REPLIES 6
Jeeshan
Honored Contributor
Solution

Re: Script to capture cpu and memory utilization every hour

Put this script in crontab so it will run as per your requirements

#!/bin/ksh
#######Script start########

dt=$(date +%d%m%Y_%H%M)
hname=$(hostname)

touch ~/$hname.$dt

echo "######VMSTAT outputs###########" >> ~/$hname.$dt
vmstat 1 5 >> ~/$hname.$dt

echo "######sar -u 5 5###############" >> ~/$hname.$dt
sar -u 5 5 >> ~/$hname.$dt
a warrior never quits
George Spencer_4
Frequent Advisor

Re: Script to capture cpu and memory utilization every hour

Here is a script that we use. It is very similar to the previous suggestion.
avizen9
Esteemed Contributor

Re: Script to capture cpu and memory utilization every hour

please check this form its having good info for your question,

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1017127
Fredrik.eriksson
Valued Contributor

Re: Script to capture cpu and memory utilization every hour

You should be able to use top.

top -n 1 > output_file.txt

This should print the top page 1 time then exit.
Then use crontab to execute it every hour :)

Best regards
Fredrik Eriksson
Arturo Galbiati
Esteemed Contributor

Re: Script to capture cpu and memory utilization every hour

Hi,
I use glance to collect data about cpu, disk, mem, swap.

res-cop.ksh:
#---BEGIN
#/usr/bin/ksh
GlnCmd=/opt/perf/bin/glance
WrkDir=
GlnSyn=$WrkDir/gln_syntax_file
GlnOpt="-j60 -adviser_only -nosort -iterations 2 -bootup -syntax $GlnSyn"
ResLog=$(date +%Y%m)-res-cop.log
#echo -- MM/DD/YY HH:MM:SS CPU DSK MEM SWA
$GlnCmd $GlnOpt 2>/dev/null |tail +2 >>$WrkDir/$ResLog
#---END

gln_syntax_file:
print "-- ",
gbl_statdate,
" ",
gbl_stattime,
" ",
gbl_cpu_total_util|3|0,
" ",
gbl_disk_util_peak|3|0,
" ",
gbl_mem_util|3|0,
" ",
gbl_swap_space_util|3|0

It creates a yyyymm-res-cop-log file which contains data collected.

HTH.
Rgds,
Art
mohdamir
Frequent Advisor

Re: Script to capture cpu and memory utilization every hour

Closed