Shell script validation using process.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script validation using process.
# 8  
Old 02-24-2012
Not familiar with your O/S but if you have the "ptree" and "pgrep" commands they could prove useful.
# 9  
Old 02-24-2012
There's infinitely many approaches, parameters are just the most reliable.

Since we know you have linux:

Code:
$ cat ppid.awk

BEGIN {
        OFS="\t"
        D=0

        do
        {
                D++

                while(getline<("/proc/" PID "/status"))
                {
                        if($1 == "Name:")       NAME=$2
                        if($1 == "PPid:")       PPID=$2
                }

                close("/proc/" PID "/status");

                print D, "PID", PID, "PPID", PPID, "NAME", NAME;

                PID=PPID;       NAME="";        PPID=""
        } while(PID>0)

        exit 1
}

$ awk -v PID="$$" -f ppid.awk

1       PID     6925    PPID    6924    NAME    bash
2       PID     6924    PPID    6921    NAME    sshd
3       PID     6921    PPID    3937    NAME    sshd
4       PID     3937    PPID    1       NAME    sshd
5       PID     1       PPID    0       NAME    init

$

# 10  
Old 02-24-2012
Thanks a lot for your reply.

1) My current shell script(myscript.sk where I am doing validation) process is,

myid1 23346 22511 02:54 ? 00:00:00 /bin/ksh /home/myid1/myscript.ksh

So in the shell script PID=$$ will fetch the value as, PID=23346.

2) The parent process of 23346 is 22511, which is,

myid1 22511 22510 0 02:53 ? 00:00:00 /usr/bin/ksh /tmp/har37sbp6

so the $PPID will return the value as "22511" when I get it from the /proc/ PID /status system file.

3) The parent ID of 22511 process is 22510, which is,

myid1 22510 25146 002:53 ? 00:00:00 /host1harvest/dstart/harrefreshd 50000 /host1harvest/Harvestr/5

So, will I get the process name as "/host1harvest/dstart/harrefreshd" if I use the below script. Please advise. I am sorry, if I had typed wrongly in my previous posts.
# 11  
Old 02-25-2012
What below script? You didn't post anything.

Have you tried the one I posted?
This User Gave Thanks to Corona688 For This Post:
# 12  
Old 02-29-2012
Thanks a lot. Now, instead of calling the BEGIN inside a ppid.awk file, I planned to use it in a function get_process_name(). When I used it in a method, I am not getting the process name. How to change ppid.awk into a function in shell script? please advise.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with validation of URLs in shell script

hello every one I wrote the script to validate all the urls from my server . sourcing text file which contains the list of urls and trying to check every url and based on response printing url is up or not. the issue when i use the below code with url is printing url exist and and in loop it's... (3 Replies)
Discussion started by: markjohn1
3 Replies

2. UNIX for Dummies Questions & Answers

Validation to be added in the shell script

I need help with one of my shell script. The script is working fine but i need to add two condition - i need to get rid of all the below ftp messages and need to have only ftp completed or failed message. example when i run the script i get below lines - Connected to xxxx 220 (vsFTPd... (1 Reply)
Discussion started by: chandraprakash
1 Replies

3. Shell Programming and Scripting

String validation in shell script

Hi All, I am a newbie...I would like to have a function which ll check if a file contains valid strings before "=" operator. Just to give you my requirement: assume my file has content: hello= gsdgsd sfdsg sgdsg sgdgdg world= gggg hhhh iiiii xxxx= pppp ppppp pppp my... (1 Reply)
Discussion started by: rtagarra
1 Replies

4. Shell Programming and Scripting

Validation in shell script.

PICKUPDIR=/home/ready/ DROPDIR=/home/downloaded/ TODAY=$(date '+%d%m%y') LOGFILE=xyz-$TODAY.log ########### #FUNCTIONS# ########### #function to perform file transfer to servercopy folder opalO () { cd $PICKUPDIR for fileName in `ls -1 TES_ONE*` do cp $fileName $DROPDIR done } >>... (4 Replies)
Discussion started by: ravigupta2u
4 Replies

5. Shell Programming and Scripting

Kill a process from parent shell within a shell script

Hi, I am looking for a solution for the following problem: Im Using tcpdump within a shellskript started in a subshell by using brackets: ( /usr/sbin/tcpdump -i ... -c 1 ) - I want the outout of tcpdump saved in a variable - Than tcpdump-Process in the Subshell should be killed - and I... (6 Replies)
Discussion started by: 2retti
6 Replies

6. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

7. Shell Programming and Scripting

EMail Address Validation (Shell Script)

Hi, Can anyone provide me the code snippet for EMail Address Validation. User is going to enter the email address in form window. I need to validate the format is correct. Thanks in Advance BS (3 Replies)
Discussion started by: balajiora
3 Replies

8. Shell Programming and Scripting

shell script data & time validation

How to validate a date and optionly a time in shell scripting when i get the date and time as pararmeters that sent out with the call of the file? (in my case sh union.sh `first parameter ,second parameter...` (4 Replies)
Discussion started by: tal
4 Replies

9. Shell Programming and Scripting

Test File Reading & Validation using Shell script

Please help develop script for below requirement -------Sample file------------------------------- HSVSHOSTRECON 20090115011817BP DARMAR60064966247003504720000000000000000000066626000000000000133000003D003463001332 ... (14 Replies)
Discussion started by: niraj_bhatt
14 Replies

10. Shell Programming and Scripting

Need help in file validation by shell script

Hi I am new to this forum.I need a help in the following: We receve pipe delimited file with transaction ID,tran_date,Quest_cd,Ans_cd,ans_value. Same transaction ID can be repeated with different quest_cd and ans_cd. Basically I need to check if a perticular pair of quest_cd and ans_cd... (1 Reply)
Discussion started by: srichakra
1 Replies
Login or Register to Ask a Question