Getting System Load in Perl

Use qx() to capture the output of uptime and parse the load averages: # 1-minute load average my $load1 = qx(uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f1); # 5-minute load average my $load5 = qx(uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f2); # 15-minute load average my $load15 = qx(uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f3); Note: use qx() not exec() – exec replaces the current process and doesn’t return.