1833385 Members
3531 Online
110052 Solutions
New Discussion

shell script

 
Raghu Kanth C.L
Advisor

shell script

Hello,

I am not so savy in writing awk scripts .Please guide me to write a script to get the required values.
The senario is as follows.

The output of a command (which is the output of the command iostat in solaris) is as follows.
iostat -D -l 2 1 4
sd0 sd6
rps wps util rps wps util
0 5 3.0 0 0 0.0
0 0 0.0 0 0 0.0
0 0 0.0 0 0 0.0
0 0 0.0 0 0 0.0

Here I need to store the disk names (viz.sd0 and sd1) and also for each disk, the utilization column,i.e the thrid field for each disk needs to added and the average should be taken and to be stored in another variable.Here the disks is not alwas same it depends on the number of disk available on the system.


Thanks in Advance,
Regards,
Raghu
he who can does he who cannot, preaches
1 REPLY 1
Ramkumar Devanathan
Honored Contributor

Re: shell script

$ cat getutil.awk
BEGIN{}
{
if (NR==1) { split($0,disks);getline; }
if (NR==2) { getline; }
utilcol=3;
for (ct=1;ct <= ndisks; ct++)
{
disks[ct,sum] += $utilcol;
utilcol += 3;
if (utilcol > NF) { break; }
}
}END{
for (ct=1;ct<=ndisks;ct++){
printf ("%s %f\n", disks[ct], disks[ct,sum]/(NR-2));
}
}
<<<<<<<<<<<<<<<<

call as follows -

$ export ndisks=2
$ iostat -D -l $ndisks 1 4 | awk -f getutil.awk -v ndisks=$ndisks

HTH.

- ramd.
HPE Software Rocks!