I am writing a script to collect system usage data. I want to repeat the ps command every 10 seconds. How can I do that?
open (out, "> system_util.txt"
open(PSEF_PIPE,"ps -ef|"
while (<PSEF_PIPE>) {
chomp;
@psefField = split(' ', $_, 8);
$pid[$i] = $psefField[1];
$uid{$pid[$i]} = $psefField[0];
$ppid{$pid[$i]} = $psefField[2];
($min,$sec) = split(/:/,$psefField[6]);
$time{$pid[$i]} = $min * 60 + $sec;
$ucmd{$pid[$i]} = $psefField[7];
$i++;
print (out " $psefField[1], $psefField[0], $psefField[2], $min $sec, $psefField
[7] \n" >system_util.txt;
}
open (out, "> system_util.txt"
open(PSEF_PIPE,"ps -ef|"
while (<PSEF_PIPE>) {
chomp;
@psefField = split(' ', $_, 8);
$pid[$i] = $psefField[1];
$uid{$pid[$i]} = $psefField[0];
$ppid{$pid[$i]} = $psefField[2];
($min,$sec) = split(/:/,$psefField[6]);
$time{$pid[$i]} = $min * 60 + $sec;
$ucmd{$pid[$i]} = $psefField[7];
$i++;
print (out " $psefField[1], $psefField[0], $psefField[2], $min $sec, $psefField
[7] \n" >system_util.txt;
}