Hello kind Monks,
I am trying to retrieve from a "ps -ef" specific strings using a simple regex.
My code looks something like that:
my $logname = `logname`; chomp($logname);
my $output = `ps -ef | grep $logname`;
if ($output =~ /.*\/export\/home\/$logname\/(.*)\/bin\/.*/m){
print "$`\n";
}
with the output being something like:
root 28834 28833 0 Aug25 ? 00:00:00 login -- mylogname2
root 29853 29852 0 Aug25 ? 00:00:00 login -- mylogname2
root 5379 5378 0 Aug26 ? 00:00:00 login -- mylogname2
root 5454 5453 0 Aug26 ? 00:00:00 login -- mylogname2
509 6710 1 0 00:20 ? 00:00:28 /export/home/mylogname/folder1/bin/binary
509 6729 1 0 00:35 ? 00:00:11 /export/home/mylogname/folder2/bin/binary
522 7996 1 0 07:00 ? 00:00:07 /export/home/mylogname2/folder1/bin/binary
509 7997 1 0 07:00 ? 00:00:01 /export/home/mylogname/folder3/bin/binary
522 8045 1 0 07:02 ? 00:00:02 /export/home/mylogname2/folder4/bin/binary
However the result of the print gives me the first four line while I am trying to folder1, folder2 and folder3 since my logname is "mylogname".
What am I doing wrong?
Thank you
PS: I tried also with a regex like that:
^.*\/export\/home\/$logname\/(.*)\/bin\/.*$
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.