Need help to parse iostat command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to parse iostat command output
# 1  
Old 06-01-2016
Need help to parse iostat command output

Hi,

I got the code below is one of the threads from this forum.

Code:
lineCount=$(iostat | wc -l)
numDevices=$(expr $lineCount - 7);

iostat $interval -x -t |
awk -v awkCpuFile=$cpuFile -v awkDeviceFile=$deviceFile -v awkNumDevices=$numDevices '
BEGIN {
	print "date/time,%user,%nice,%system,%iowait,%steal,%idle" > "awkCpuFile"
	print "date/time,device,rrqm/s,wrqm/s,r/s,w/s,rsec/s,wsec/s,avgrq-sz,avgqu-sz,await,svctm,%util" > "awkDeviceFile"
}
NF==2{
	s=$0
	getline; getline; $1=$1
	gsub(/ /,",",$0)
	print s "," $0 > "awkCpuFile"	
}
/Device:/{
	for (i=0; i<awkNumDevices; i++) {
		getline; $1=$1
		gsub(/ /,",",$0)
		print s "," $0 > "awkDeviceFile"
	}
}'

Once this script is executed,
I am able to see the device statistics in the output file "awkDeviceFile" but there is no value displayed in the CPU statistics file "awkCpuFile"

Could you please let me know what could be the reason for the same?
# 2  
Old 06-01-2016
Please always post the entire script - in your above snippet, several variables are unset and thus could negatively influence the script's execution.

Amongst which is $cpuFile - if that is empty, no file is produced. Other reasons might be
- NF != 2, so that action is not executed and no cpu values printed..
- All print redirections happen to string constants, not the variables defined, so the produced files' names may not match your expectations.
# 3  
Old 06-01-2016
Dear RudiC,

Thanks for pointing out the possibilities in quick time.
The script works fine now with only one change:
Instead of NF==2, I used NF==3 and now am able to print both cpu statistics as well as Device statistics

Best Regards,
Gopi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help to get the parsed output of "iostat" command

Hi, I have a requirement where parsed output from various linux commands like top, netstat, iostat, etc. will be the input for one javascript with the parsed output from these commands converted to JSON format For "iostat" command, since there are two outputs - one w.r.t CPU utilization and... (2 Replies)
Discussion started by: gopivallabha
2 Replies

2. Solaris

Asvc_t values in iostat output

Noticed that asvc_t values in iostat command outputs are mostly more than 100 in our previous iostat analysis. Also found the following detail from an alternate site IO Bottleneck - Disk performance issue - UnixArena ---- 1. asvc_t average service time of active transactions, in... (2 Replies)
Discussion started by: saraperu
2 Replies

3. Solaris

Unmatched ssd create huge unuseful iostat output

My scheduled collection of statistics is giving very large output because of an high number of ssd device not associated to any disk The iostat -x command is collecting statistics from them and the output is very large. I.g. if a run iostat -x|tail +3|awk '{print $1}'>f0.txt.$$ iostat... (5 Replies)
Discussion started by: sun-mik
5 Replies

4. UNIX for Dummies Questions & Answers

How to parse 2 particular lines from Command output

Hi All, I need help on the following req. I am getting output of a command as follows: 16377612 total memory 3802460 used memory 2827076 active memory 681948 inactive memory 12575152 free memory 477452 buffer memory I want to compute used... (1 Reply)
Discussion started by: mailsara
1 Replies

5. Filesystems, Disks and Memory

iostat output vs TPC output (array layer)

Hi Guys, I've been having some arguments with my colleagues about one thing. Always my thought was that as as far as disk performance is concern by looking at the output of the iostat command (AIX) you would be able to identify if you have a hot disk and then by moving some files out that disk... (3 Replies)
Discussion started by: arizah
3 Replies

6. Shell Programming and Scripting

Perl Parse word from command output

Hello, I used the following script to conect to cisco router: #!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Opsware::NAS::Connect; my($host, $port, $user, $pass) = ('localhost','$tc_proxy_telnet_port$','$tc_user_username$','$tc_user_password$'); my $device =... (5 Replies)
Discussion started by: ahmed_zaher
5 Replies

7. Shell Programming and Scripting

finding greatest value in a column using awk from iostat output in linux

Friends, Need some help. On linux i have to run iostat command and in each iteration have to print the greatest value in each column. e.g iostat -dt -kx 2 2 | awk ' !/sd/ &&!/%util/ && !/Time/ && !/Linux/ {print $12}' 4.38 0.00 0.00 0.00 WHhat i would like to... (15 Replies)
Discussion started by: achak01
15 Replies

8. Shell Programming and Scripting

Formatting output from iostat

So I use Cacti for monitoring IO statistics on my servers, now originally I couldnt monitor Multipath deviced servers as they have alot of /dev/sdxx and /dev/emcpowerxx, I have devised a method of trimming them down to just the actual devices but the issue is the output looks like so. # iostat... (0 Replies)
Discussion started by: RiSk
0 Replies

9. UNIX for Advanced & Expert Users

iostat output what is that mean

Hi all, i have run iostat -em, and get below result. Can i know what is this output meaning, and how to fix that problem. iostat -em ---- errors --- device s/w h/w trn tot sd7 0 1 0 1 sd8 1 1 0 2 sd9 0 1 0 1 sd10 0 ... (2 Replies)
Discussion started by: foongkt5220
2 Replies

10. Solaris

iostat -e / -E output explanation

Hi all, hope you are having a nice day, its nice and warm today in Canberra Australia. iostat -e / -E reports soft and hard errors. Any idea what these are exactly? All I hear are I/O's failing and needing to retry, but no cause as to why they fail. My SUN guru tells me its our EMC SAN... (1 Reply)
Discussion started by: scottman
1 Replies
Login or Register to Ask a Question