Get parent script name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get parent script name
# 1  
Old 02-24-2012
Get parent script name

Hi, my question is similar to my earlier post from 2009 which is Closed now
https://www.unix.com/shell-programmin...ript-name.html

script child.sh can be called by any script say, parent1.sh, parent2.sh, parent3.sh,...
child.sh should be able to say what's it's parent script command line

child.sh
Code:
echo "My command line is $0 $@"
echo "My parent command line is $(cat /proc/$PPID/cmdline)"

parent1.sh
Code:
child.sh c1 c2

If i run this command:
parent1.sh p1 p2 p3

i should see the result:
My command line is child.sh c1 c2
My parent command line is parent1.sh p1 p2 p3

I took the 'cat /proc/$PPID/cmdline' line from 'frans' reply in the Closed thread

However /proc directory is not available
Our is HP-UX 11.11 box, where can i find the file that stored the cmdline information by process id?

Thanks,
-srinivas yelamanchili
# 2  
Old 02-25-2012
As a work around you can make use of this:
Code:
pandeeswaran@ubuntu:~/training$ sh parent1.sh p1 p2 p3
My parent process is sh parent1.sh p1 p2 p3
pandeeswaran@ubuntu:~/training$ cat child.sh
pp=`ps -ef|grep $PPID|head -1|awk '{for (i=8; i<=NF; i++) print $i}'`
echo  "My parent process is "${pp}""
pandeeswaran@ubuntu:~/training$

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 capture exit code of child script and send it to parent script?

#!/usr/local/bin/bash set -vx /prod/HotelierLinks/palaceLink/bin/PalacefilesWait /prod/HotelierLinks/palaceLink/bin/prodEnvSetup 03212013 & if then echo "fatal error: Palace/HardRock failed!!!!" 1>&2 echo "Palace Failed" | mail -s "Link Failed at Palace/HardRock" -c... (1 Reply)
Discussion started by: aroragaurav.84
1 Replies

2. Shell Programming and Scripting

Stop child script by stoping parent script

Hi everyone, I have this problem with a script I'm writting. I want to execute a code running in the background several times through a script. I am writting it like that parent_script for a in 1 2 3 4 5 do exec test -n $a done What I want to do is when parent_script is killed,... (0 Replies)
Discussion started by: geovas
0 Replies

3. Solaris

Help in changing the Parent id of a script

HI I want to run a script as new process. for example, I have two script A and B. From A I am calling B, but When I do ps -ef for the script B the parent ID should not be A' ID. Please help me Thanks & Regards Ramu (3 Replies)
Discussion started by: ramukumar
3 Replies

4. Shell Programming and Scripting

Parent Script exiting with child script

PARENT SCRIPT #!/bin/ksh # . $HOME/.profile . /etl/estdm2/DEV/scripts/DM_ENV_VARS.ksh DEV DB echo "CALLING CHILD SCRIPT" . /${SCRIPT_DIR}/DM_CHild.ksh -x HRDATA.dat -e $sEnv -d Wait_Time *****THE PARENT SCRIPT EXITS HERE ******** *****whether the file is found or not******* ... (2 Replies)
Discussion started by: sumeet
2 Replies

5. Shell Programming and Scripting

Get current and parent script name

Hi, i have a script a.sh that calls b.sh Both take parameters a.sh { b.sh p1 p2 p3 } b.sh { GIVEN_CMD="`basename $0` $@" echo "${GIVEN_CMD} } Now when i run: a.sh q1 q2 It prints only a.sh q1 q2 Inside b.sh, how can i print both the script names and their parameters passed? (6 Replies)
Discussion started by: ysrini
6 Replies

6. Shell Programming and Scripting

Script, child kills parent

Hello everyone, I'm trying to write a script, i would like to say the child kills the parent, how would i do that? (2 Replies)
Discussion started by: jessy21
2 Replies

7. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

8. Shell Programming and Scripting

returning to the parent shell after invoking a script within a script

Hi everybody, I have a script in which I'm invoking another script which runs in a subshell. after the script is executed I want to return to the parent shell as some variables are set. However i'm unable to return to my original shell as the script which i'm calling inside is invoked in... (5 Replies)
Discussion started by: gurukottur
5 Replies

9. Solaris

How to know parent script

:confused: Can some one advise me how to know the parent script from a child script. ex: i can call 1.sh or 2.sh from 3.sh so wot is the command to know from which script 3.sh is called from? (1 Reply)
Discussion started by: raki
1 Replies

10. Shell Programming and Scripting

return valuse from child script to parent script

Hi, I am trying to return a value from child script to a parent script just as a function does. The child script will look for a file and if exists will return 1 else 0. I need to capture the status 1 from child script in the parent script and proceed further. if 0, i need not do... (1 Reply)
Discussion started by: borncrazy
1 Replies
Login or Register to Ask a Question