Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

repeating ps command every 10 secs 1

Status
Not open for further replies.

itsmythg

Technical User
Apr 4, 2001
34
US
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 &quot; $psefField[1], $psefField[0], $psefField[2], $min $sec, $psefField
[7] \n&quot;) >system_util.txt;
}


 
take a look at crontab, its wicked...

You can schedule things in there to run as often and as much as you like...

Be warned, make sure your scripts are suitable to be run every 10 secs...
 
As far as I know crontab will only handle time in minute segments (that's minute as in time, not as in very small!). You could try writing a small script with a minute's worth of your ps command in it (ie 6 insances), putting a sleep 10 between each invocation of it in the script. Then just add this to your crontab to run every minute.

You might find that you end up with some very big files!

Good luck.
 
while true
do
ps -ef (or whatever other choice of options)
sleep 10
clear (if you are displaying onto a screen and you want to
replace the previous display each time)
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top