Perl – system load

To find the system load use the following perl snippet :

1) System load of last one minute :

my $system_load = exec('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f1');
my $system_load = qx('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f1');

2) System load of last 5 minutes :

my $system_load = exec('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f2');
my $system_load = qx('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f2');

3) System load of last 15 minutes :

my $system_load = exec('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f3');
my $system_load = qx('uptime | awk -F "load average: " \'{ print $2 }\' | cut -d, -f3');
Advertisements

Published by

Shafiq Alibhai

http://shafiq.in

5 thoughts on “Perl – system load”

  1. Sorry but this is plain wrong. exec replaces the perl process and does not return. Your variables will never be used and will never hold any of the values in them.

    The examples might print the correct values to the screen but this has nothing to do with perl.

    If you need the output of a shell command use backticks or qx().

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s