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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
continuously monitor program

 



nychris
New User

Sep 18, 2013, 12:23 PM

Post #1 of 4 (2018 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.


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


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.


Laurent_R
Veteran / Moderator

Sep 19, 2013, 10:33 AM

Post #2 of 4 (2012 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.


nychris
New User

Sep 19, 2013, 11:17 AM

Post #3 of 4 (2010 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

muni_stap_monitor.pl - I would run this which starts muni_stap_start.pl, 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



Code
$ cat muni_stap_monitor.pl 
#!/usr/bin/perl
open(STAP, "/root/muni_stap_start.pl |");
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;



Code
>$ cat muni_stap_start.pl 
#!/usr/bin/perl
# output autoflush = 1
$| = 1;
system("/root/sigmon_muni.stp");



Laurent_R
Veteran / Moderator

Sep 20, 2013, 7:43 AM

Post #4 of 4 (1996 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:


Code
open(STAP, "/root/muni_stap_start.pl |") 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