CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
continuously monitor program


New User

Sep 18, 2013, 12:23 PM

Post #1 of 4 (2675 views)
continuously monitor program Can't Post

I have a systemtap script (loop.stp) that continuously runs and prints output periodically. I want to monitor this output from a perl script. It seems that this only prints output when a command exits. For example, if I change this to /bin/ps, it does print the entire output when the command exits. I need it to print output as it occurs since the program will never end.

open(STAP, "/root/loop.stp |"); 
while ( <STAP> ) {

I found a hack that will print the output, but I can't do anything with the data. If I start loop.stp from within another perl script and add "$| = 1" to that perl script, and then call the 2nd perl script it does show the output from loop.stp but all it does is print to the screen. If I add statements to the while loop they don't do anything.

Veteran / Moderator

Sep 19, 2013, 10:33 AM

Post #2 of 4 (2669 views)
Re: [nychris] continuously monitor program [In reply to] Can't Post

Please show these two scripts, we can't help correct something that we don't see.

New User

Sep 19, 2013, 11:17 AM

Post #3 of 4 (2667 views)
Re: [Laurent_R] continuously monitor program [In reply to] Can't Post

I didn't include the other scripts because I didn't think they were a workable solution. Here's what I was trying:

sigmon_muni.stp - this is the systemtap script that periodically prints data that I want to act on - I would run this which starts, which in turn runs sigmon_muni.stp. The output of sigmon_muni.stp is printed to the screen, but I can't do anything with it from the perl script

$ cat 
open(STAP, "/root/ |");
while $line ( <STAP> ) {
if ($line =~ /loop1/) {
## anything I put here does not work. I want to read the data that is being printed to the screen and perform an action if it meets certain requirements
close STAP;

>$ cat 
# output autoflush = 1
$| = 1;

Veteran / Moderator

Sep 20, 2013, 7:43 AM

Post #4 of 4 (2653 views)
Re: [Laurent_R] continuously monitor program [In reply to] Can't Post

Try to see if you open works and actually succeeds opening something:

open(STAP, "/root/ |") or die "open failed $!";

Second, if the open works fine, try to simply print the lines you read from <STAP>, to see if it is what you expect.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives