ps command through shell and perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ps command through shell and perl
# 1  
Old 02-16-2011
ps command through shell and perl

Hi ,

I have a ps command inside perl script :
Code:
ps -ef | egrep tail_file.pl | egrep -v egrep | awk '{print $2}' | egrep $pid


through shell it's working fine . The same coammnd when executed through PERL , it'd displaying all the results

Code:
oracle   10141     1  0  2010 ?        00:00:03 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S hmdalu11 -F /opt/oracle/admin/hmdalu11/bdump/alert_hmdalu11.log -R ORA -e

here 2010 is not in 2 column and PERL is returning this .

Is there diff way to use inside PERL?

Thanks
# 2  
Old 02-16-2011
I don't understand the egrep $pid on the end, is the PID of the tail_file.pl process in that environment variable? If so is this set before the perl script runs or within the perl script?

What are you trying to achieve, I'd assume you are trying to check that process $pid is still running?
# 3  
Old 02-16-2011
Yes, I want to see for this pid , the tail file is running or not. $PID , I am setting inside perl.

Code:
oracle    9601  7734  0 16:16 pts/13   00:00:00 grep tail_file
oracle   10141     1  0  2010 ?        00:00:03 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst1 
gdambh   17619 26293  0 15:23 pts/23   00:00:00 vi tail_file.pl
oracle   18776     1  0 Jan28 ?        00:00:00 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst2 
oracle   30769     1  0 14:17 ?        00:00:00 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst3 
oracle   30896     1  0 14:17 ?        00:00:00 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst3 
oracle   30897     1  0 14:17 ?        00:00:00 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst4 
oracle   30898     1  0 14:17 ?        00:00:00 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst5 
oracle   30899     1  0 14:17 ?        00:00:00 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst6

so, on the second column, if there is matching PID that I am sedning .

If I execute this command in shell:

oracle@host2:/opt/dba/oraadmin/inst1/log ACP$ ps -ef | egrep tail_file.pl | egrep -v egrep | awk '{print $2}' | egrep 2010
oracle@host2:/opt/dba/oraadmin/inst1/log ACP$

it didn't return any values.

But when I am executing this command inside perl , it's returning:

oracle 10141 1 0 2010 ? 00:00:03 /opt/dba/perl-5.8.8/bin/perl -S /opt/dba/oraadmin/tools/tail_file.pl -S inst1
# 4  
Old 02-16-2011
Code:
pgrep -f tail_file.pl

As pgrep groks regular expressions you could use the $ anchor ...

Andrew
# 5  
Old 02-16-2011
Thankyou all . I found solution to my problem :

we need to write it as print \$2.

It's PERL ..........Smilie
# 6  
Old 02-17-2011
Quote:
Originally Posted by talashil
Thankyou all . I found solution to my problem :

we need to write it as print \$2.

It's PERL ..........Smilie
Your problem is using a complicated pipeline - with awk of all things - in a perl script.

Whenever I see a pipeline with
Code:
awk '{print $2}'

in it my first reaction is always: Is there a better way? There invariably is. When ps is in that pipeline there is always a better way using pgrep and ps -o

Given you presumably are looking for $pid why not:
Code:
ps -p$pid >/dev/null

and check the exit status?

Sorry about the rant - I felt ignored Smilie

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use shell command on Perl scritps?

On our OS I don't have Perl df command. How can I use shell commands from Perl scripts? (6 Replies)
Discussion started by: digioleg54
6 Replies

2. Shell Programming and Scripting

Usage of shell variable in perl command

Hi, I have a shell script, In which i have variable "var1" and some perl command inside shell script. export var1='coep -n rst-a2p-hinje.vci.all.com -c' perl -pi -e 's/^/coep -n rst-a2p-hinje.vci.all.com -c /' command.txt currently I am adding value of var1 in command.txt file by... (2 Replies)
Discussion started by: rakeshtomar82
2 Replies

3. Shell Programming and Scripting

Use shell variable in perl command line

Hi, I would like to use a shell variable $amp in my perl command line. for fa in $WORKSPACE/*.fa; do amp=`grep ">.*" $fa | sed -e's#>\(.*\)#\1#g'` ampsam="$WORKSPACE/$base/$base.$amp.sam" sqheader=`grep "^@SQ.*SN:$amp.*" $sam` printf "$sqheader\n" >> $ampsam ... (3 Replies)
Discussion started by: jdilts
3 Replies

4. Shell Programming and Scripting

perl: Command works in terminal, but not in shell script

Hi, the following command works in the terminal no problem. samtools view -h rawlib.bam | perl -ne '{ @line = split( /\s+/ ); $match = 0; while( $line =~ /(\d+)M/g ) { $match = $match + $1 } if( $match >= 80 || $_ =~ /^\@/ ) { print $_ } }' | java -Xmx12G -jar... (8 Replies)
Discussion started by: jdilts
8 Replies

5. Shell Programming and Scripting

Passing perl variable to shell command

Can we pass perl variable to shell commands. If yes, please give some example. (2 Replies)
Discussion started by: Anjan1
2 Replies

6. UNIX for Dummies Questions & Answers

perl command in shell not working

perl script i am using for search and replace is not working as expected... I am using it for in-place search/replace. I am new to perl, can someone please help me solving the issue here. ########SCRIPT #!/bin/sh var="abc" var2="def" perl -pi -e 's/${var}/def/g' testfile exit 0 ... (0 Replies)
Discussion started by: manishma71
0 Replies

7. Shell Programming and Scripting

running shell command in Perl script

Does not work. #!/usr/bin/perl $etcdir = 'ls -l /etc'; print $etcdir; #END ------------result-------- #perl -w abc123.pl ls -l /etc # This method works. #!/usr/bin/perl $etcdir = system("ls -l /etc"); print $etcdir; #END (2 Replies)
Discussion started by: dplinux
2 Replies

8. Shell Programming and Scripting

Shell Command execution through PERL

Hi Guys, I wish to execute some shell commands through PERL. Here is what I desire to do 1) I wish to find list of directories in current working location 2) Then go in each directory and execute few commands like a) rm -rf *.log (Shell command) b) coreBuilder -f cb_tests.tcl (Some... (6 Replies)
Discussion started by: hardik_snps
6 Replies

9. UNIX for Advanced & Expert Users

Invoking shell script with perl command.

Hi All, I am using the following command to invoke the shell script from a perl command. perl -i.bak -pe'BEGIN { $cmd = "/opt/coreservices/tomcat-5.5.9/bin/digest.sh -a sha"; } s/(password=")(*)/ $1.`$cmd $2|cut -d: -f2|tr -d "\n"` /e ' $CATALINA_HOME/conf/tomcat-users.xml I need... (1 Reply)
Discussion started by: nua7
1 Replies

10. Shell Programming and Scripting

perl command help in shell script

Hello friends , I need a help how to call the variable which has define in the shell script in the perl command line. example of the shell scrip : str="hell0" i want print the value of this variable in the perl command line. perl -e 'print $str' but this is not working . can... (2 Replies)
Discussion started by: venky_2_2000
2 Replies
Login or Register to Ask a Question