Re: beginners-help@perl.org
- From: someone@xxxxxxxxxxx (John W. Krahn)
- Date: Thu, 27 Dec 2007 07:03:24 -0800
Anirban Adhikary wrote:
Hi all
Hello,
Subject: beginners-help@xxxxxxxx
Please put the subject of your email on the Subject line.
I want to assign the each column of the following file in a separate
variable.
2864 oracle 0.0
0.2/home/oracle/u01/app/oracle/product/10.2.0/db_1/inventory/bin/tnslsnr
LISTENER -inherit
2872 oracle 0.0 0.6 ora_pmon_orcl
2874 oracle 0.0 0.5 ora_psp0_orcl
2876 oracle 0.0 1.2 ora_mman_orcl
2878 oracle 0.0 4.4 ora_dbw0_orcl
2880 oracle 0.0 1.7 ora_lgwr_orcl
2882 oracle 0.0 1.0 ora_ckpt_orcl
2884 oracle 0.0 5.0 ora_smon_orcl
2886 oracle 0.0 0.8 ora_reco_orcl
2888 oracle 0.0 2.3 ora_cjq0_orcl
2890 oracle 0.0 4.7 ora_mmon_orcl
2892 oracle 0.0 0.7 ora_mmnl_orcl
2894 oracle 0.0 0.5 ora_d000_orcl
2896 oracle 0.0 0.5 ora_s000_orcl
2904 oracle 0.0 0.5 ora_qmnc_orcl
2922 oracle 0.0 2.2 ora_q000_orcl
2924 oracle 0.0 0.5 ora_q001_orcl
20186 oracle 0.0 5.3 oracleorcl (LOCAL=NO)
22556 root 0.0 0.1 sshd: oracle [priv]
22558 oracle 0.0 0.0 sshd: oracle@pts/7
22559 oracle 0.0 0.0 -bash
22877 oracle 0.0 0.9 ora_j000_orcl
For this I used the following code
#!/usr/bin/perl -w
@arr1 = qw/java oracle/;
@arr2 = `ps -eo pid,user,pcpu,pmem,args | grep -v grep | grep $arr1[1]`;
$length= $#arr2;
for($i=0;$i<=$length;$i++)
{
chomp;
$val=$arr2[$i];
#print $val."\n";
@arr = split(/\s+/,$val);
print $arr[1]."\n";
But I am not getting the desired output.
This may work better:
#!/usr/bin/perl
use warnings;
use strict;
my $user = 'oracle';
open my $ps, '-|', 'ps', '-eo', 'pid,user,pcpu,pmem,args'
or die "Cannot open 'ps' pipe: $!";
while ( my $line = <$ps> ) {
my @fields = split ' ', $line, 5;
print $fields[ 1 ] if $fields[ 1 ] eq $user;
}
close $ps or warn $! ? "Error closing 'ps' pipe: $!"
: "Exit status $? from 'ps'";
__END__
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- beginners-help@perl.org
- From: Anirban Adhikary
- beginners-help@perl.org
- Prev by Date: beginners-help@perl.org
- Next by Date: RE: beginners-help@perl.org
- Previous by thread: beginners-help@perl.org
- Next by thread: RE: beginners-help@perl.org
- Index(es):
Relevant Pages
|
|