script to extract PID


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to extract PID
# 1  
Old 09-12-2012
script to extract PID

Can anyone explain the below script which is used to extract the PID?
Why they are taking from 10 character and getting the sub string?

Note:variable pid has been assigned the PID value initially as below.
pid=`sed 's@FILNAME@'$destFil'@g' $scriptname |sed 's@SRCFILE@'$sourceFil'@g' |sed 's@CDNODE@'$CdNod'@g' |sed 's@TEMPL@'$FIL_LOCAT'@g'|sed 's@INDIC@'$acc_id'@g' | $CDCMND -r | grep "_CDPNUM_"`



len1=`expr length "$pid"`
len2=`expr $len1 - 9`
pid=`expr substr "$pid" 10 $len2`

Last edited by bk_12345; 09-12-2012 at 09:19 AM..
# 2  
Old 09-12-2012
The reason behind is simple... Here you are trying to capture the PID of a Connect Direct process (CD) so your pid will have something like below

Code:
 
_CDPNUM_ xxxxxx

as you can see _CDPNUM_<space> makes up 9 character so you have to take the actual pid from 10 onwards Smilie
# 3  
Old 09-12-2012
thank you moderator
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need script to monitor pid.

Need Cron script to monitor the process. if its down, it should alert with an email. (1 Reply)
Discussion started by: pranav987
1 Replies

2. Shell Programming and Scripting

Kill a PID using script

Hi, I wrote a script to kill a process id. I am able to kill the PID only if I enter the root password in the middle of the execution because I did not run as root i.e after i run the script from the terminal, instead of killing directly, it is killing only after entering the pass when it... (12 Replies)
Discussion started by: rajkumarme_1
12 Replies

3. Shell Programming and Scripting

pid.cleanup script.

Hi guys! I have a directory in the production environment from which i have to delete files older then 40 minutes with .pid extention. I wrote a script below for the purpose. #!/bin/bash # # Script to delete specific file older than N minutes. # OLDERTHAN="40" #40 minutes ... (6 Replies)
Discussion started by: sajid.shah
6 Replies

4. Shell Programming and Scripting

Using grep to extract PID

Hi unix experts! I need help to solve the following problem: I'm getting the prstat info: stats=`prstat 0 1` #dont worry about how many processes are running I'm aware that no all processes will be listed without the -n (specify number) then I'm doing the following to extract the... (2 Replies)
Discussion started by: sanjaybhatt6
2 Replies

5. Shell Programming and Scripting

Multiple PID for the same script

Hi All, I have scheduled one script using cron but it's not running. On investigation i have found there are 4 PIDs for the same script. Please suggest on the following: 1. Is it normal to have more than 1 PID for the script which is being run using cron command? 2. How can avoid... (3 Replies)
Discussion started by: visingha
3 Replies

6. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

7. Shell Programming and Scripting

Recursive pid script

I'm trying to create a script that allows me to determine all the pid's that spawned from an original process(ie - who's running this command).... I've created a script that searches the processes running based on an argument passed the script. It then is to get the parent pid and look that... (3 Replies)
Discussion started by: jbarnhar
3 Replies

8. Shell Programming and Scripting

How to extract the PID from 'ps -ef'

Hi I am writing a shell script in ksh where I have to grep for a process name , say XYZ from "ps -ef" and then extract it's PID. ps -ef | grep XYZ gives - " int 7738 25734 1 02:00:49 pts/tc 0:00 grep XYZ" I am thinking of replacing one or more occurrences of the space with pipe... (7 Replies)
Discussion started by: nsinha
7 Replies

9. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

10. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies
Login or Register to Ask a Question