need to extract terminal from this process -perl regx


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to extract terminal from this process -perl regx
# 1  
Old 06-30-2011
Question need to extract terminal from this process -perl regx

Hi All,

i ve a process,
Code:
user4    31779  2836  0 01:43 pts/6    00:00:00 sh /home/user/DATE/SUT_SCR/c.sh

like this i'll get so many process when in run ps -ef | grep pts | grep c.sh

i need to extract terminal id from this string. i.e pts/6, or sometimes pts/22 same way i need to do for all process, can you please help me in the regx where i need to extract terminal.

Code:
$ps = `ps -ef | grep c.sh |  grep /DATE/SUT_SCR`;
         if ($ps =~ /sh/g)
        {
            foreach $_ (split(/\n/, $ps))
              {
                if ($_ =~ /\s*(^pts\/\d+)(.*)\/c.sh$/)
                    {
                        print "$1\n";
                    }
              }
        }

this regex is not working.( =~ /\s*(^pts\/\d+)(.*)\/c.sh$/). please suggest in new regx.


thanks,
asak

Last edited by pludi; 06-30-2011 at 07:21 AM..
# 2  
Old 06-30-2011
Code:
 
ps -ef | grep pts | grep c.sh | awk  '{print $6}'

# 3  
Old 06-30-2011
Perl
Code:
 echo 'user4    31779  2836  0 01:43 pts/6    00:00:00 sh /home/use/DATE/SUT_SCR/c.sh' | perl -nle 'print $1 if/\s+(pts\/.+?)\s+/'

# 4  
Old 06-30-2011
Code:
ps -ef|awk '$6 ~ /^pts/ && /\/c\.sh$/ {print $6 }'

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Process on a specified Terminal and Socket Port does not start

Hi, I new to AIX, and I have been using Rocket UniData in it. I had to set up a Process for Data Exchange by assigning a unique Terminal and a Socket Port to that process. I ran the process for the first time and it was successful and after use I stopped the process. Now when I want to run it... (3 Replies)
Discussion started by: BejoyS
3 Replies

2. UNIX for Advanced & Expert Users

Getting the process ID of the terminal in Unix/Linux

Hi, How can we get the process id of the terminal we are using? When we logged in to unix, we have an associated terminal. we can use "tty" command to get the terminal we are using like: /dev/pts/0 I want to know the process id of this terminal. Please reply as I searched a lot but I... (8 Replies)
Discussion started by: crazybisu
8 Replies

3. Shell Programming and Scripting

Extract terminal ip and port from line

HI, I have a line conn console {conntype=serial;connhost=122.25.000.220;connport=6038;password=123!} and i am using the below code to extract the ip. while read line do if echo "$line" | grep "connhost" >/dev/null 2>&1 then echo $line TERM=`echo... (8 Replies)
Discussion started by: asak
8 Replies

4. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

5. Shell Programming and Scripting

Process not attached to terminal

Hi Folks, When i try to run schedule job on Unix server am getting following errror messges in logs pic_selection @starting on Fri Feb 5 01:53:06 GMT 2010 ------------------------------------------------------------------------------- Microfocus Cobol batch run Started: Fri Feb 5... (4 Replies)
Discussion started by: bhargav20
4 Replies

6. Shell Programming and Scripting

How to generate random strings from regx?

Hi, Guz! I'm working on a scripts compiler which needs a function to generate random strings. I think REGX may be a good solution to restrict the string format. Before DIYing I'd like asking for any existing libs or codes. Any help will be appreciated! (7 Replies)
Discussion started by: wqqafnd
7 Replies

7. UNIX for Advanced & Expert Users

Control process from different terminal (over SSH)

I pressed CTRL Z and suspended the job. then I pressed bg, The process re-started to throw output on the terminal and its not allowing me to access the prompt. its not even accepting CTRL Z. The process has been running for about 2 hours now and I want to suspend it by opening another terminal.... (3 Replies)
Discussion started by: rakeshou
3 Replies

8. UNIX for Advanced & Expert Users

how to run a process after closing the terminal

i want to execute a shell script even if the terminal is closed. how to do? (3 Replies)
Discussion started by: lakshmananindia
3 Replies

9. Shell Programming and Scripting

ksh numerical RegX

I need to distinguish between numerical characters in a script: echo "Enter a number." read num if (( $num = * )) ; then exit 0 fi this RegX does not work. Any suggestions? (5 Replies)
Discussion started by: prkfriryce
5 Replies

10. Shell Programming and Scripting

Start process in shellscript at other terminal

A programming running in tty0 crashes. In a second terminal I kill all the processes. Can i start the program again from this terminal? Yes, I can, but it starts in tty1, and when i close the terminal, the program closes. Now I want to start the program from tty1 in tty0, so i can close... (4 Replies)
Discussion started by: benschell
4 Replies
Login or Register to Ask a Question