LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2017, 09:18 AM   #1
vijaymaurya
LQ Newbie
 
Registered: Jan 2017
Posts: 23

Rep: Reputation: Disabled
Need to Help on the script


Code:
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.
 
Old 04-13-2017, 09:37 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,778

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
would be nice to insert your code between [code]here comes your script[/code] tags.
which part is unclear?
 
Old 04-13-2017, 01:31 PM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,779

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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
 
Old 04-14-2017, 02:32 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,778

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
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?
 
Old 04-23-2017, 10:37 AM   #5
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
My version (MacOS X vm_stat) prints out this:

Code:
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                               15163.
Pages active:                           1778914.
Pages inactive:                         1702917.
Pages speculative:                         7243.
Pages throttled:                              0.
Pages wired down:                        674434.
Pages purgeable:                         115842.
"Translation faults":                 736505527.
Pages copy-on-write:                   22345683.
Pages zero filled:                    388912589.
Pages reactivated:                      1824966.
Pages purged:                           1109523.
File-backed pages:                       692054.
Anonymous pages:                        2797020.
Pages stored in compressor:              569208.
Pages occupied by compressor:             13530.
Decompressions:                         3094397.
Compressions:                           4877052.
Pageins:                               11044324.
Pageouts:                                 52868.
Swapins:                                 394575.
Swapouts:                                657836.
______________________________________
So the output of different vmstats on different Unix versions appears different, I don't think this script would be helpful on my machine at all.
 
Old 04-23-2017, 11:05 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,778

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
yes, you are right, this perl script and this vmstat are not really compatible (with each other)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 09:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 01:03 AM
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 06:00 AM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 03:05 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 08:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration