I'm running Mac OSX 10.4, perl 5.8.1.
I'd like to be able to issue a command to the system, and get all of the results of my console command.
Specifically, I'm trying to find out if my perl service is running, and if not, I'll restart it.
Now, I don't want to talk about how long it took for me to determine this, but the way I'm doing it below is dependent on the size of the terminal window that the code is executing within. So if I have my window open wide enough, then my perl script gets the entire result like:
user 28066 0.0 1.0 34356 10032 p3 S+ 2:49PM 2:21.94 perl /Library/code/Theservice.pl
But if my terminal window isn't open wide enough to get the entire screen, then the code doesn't see the end part with the "Theservice", and thinks the service is dead.
There has to be a better way of trying to find out if services are running, than worrying about if the terminal window that I have my code open within is wide enough to capture the results.
Help, please?
thanks!
open(PS_F, "ps - aux | grep perl |") || die "Can't open console\n";
while (<PS_F>) {
($pid,$tt,$stat,$time,$comm,$comm1,$comm2) = split;
$comm .= ' '.$comm1.' '.$comm2;
if($comm =~ m/Theservice.pl /i) {
print "Service Already Running\n";
}
}
close(PS_F);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.