ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi All,
Hope you all are doing well.
Kindly help me to understand this script, basically this script pull the %io wait.
#!/usr/bin/perl
@sa=split("\n",`vmstat`);
@line=split(" ",$sa[1]);
for ($i=0; $i <= @line; $i++) {
if ( $line[$i] eq "wa" ) {
$j=$i;
@stat=split(" ",$sa[2]);
print "Message: CPU wait IO in percentage: $stat[$j]\n";
print "Statistic: $stat[$j]\n";
exit 0;
}
}
print "Message: ERROR: Can't find CPU wait IO (wa) in output of -vmstat- command. \n";
exit 1;
How can i understand this script.[/PHP]
Last edited by vijaymaurya; 04-13-2017 at 10:00 AM.
It processes the output of the "vmstat" command.
It splits the output into lines and stores them in sa[] array.
Then it splits a line into words and stores them in line[] array.
Then it loops through the words until it finds "wa". When found, it splits the following line into words and catches the one from the same column.
In effect it catches the word under the "wa".
There are some shortcomings though, the biggest might be the assumption that a plain "vmstat" gives values that are current. In fact they are the average since the system was booted
if you really want to understand it I suggest you to execute vmstat (just to see what will it print) and run this code inside the perl debugger, step by step and you can inspect these variables easily (according to the explanation of MadeInGermany).
But again, what is unclear?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.