Get current and parent script name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get current and parent script name
# 1  
Old 08-09-2010
Get current and parent script name

Hi,
i have a script a.sh that calls b.sh
Both take parameters
a.sh
Code:
{
  b.sh p1 p2 p3
}

b.sh
Code:
{
GIVEN_CMD="`basename $0` $@"
echo "${GIVEN_CMD}
}

Now when i run:
Code:
a.sh q1 q2

It prints only
Code:
a.sh q1 q2

Inside b.sh, how can i print both the script names and their parameters passed?

Thanks
-srinivas y.

Last edited by pludi; 08-10-2010 at 02:23 AM.. Reason: code tags, please...
# 2  
Old 08-10-2010
add one more arg $0 while calling next script

Code:
{
  b.sh p1 p2 p3 $0
}


Last edited by Scott; 08-10-2010 at 03:38 AM.. Reason: Fixed code tag
# 3  
Old 08-10-2010
a
Code:
cat /proc/$PPID/cmdline

gives you the command line of parent process
# 4  
Old 08-10-2010
Is this what you reuqire??

Code:
$ cat a.sh
{
b.sh $0 $@ a b c
}

$ cat b.sh
{
GIVEN_CMD="`basename $0` $@"
echo "${GIVEN_CMD}"
}
$ a.sh p q
b.sh a.sh p q a b c

# 5  
Old 08-10-2010
Hi, i will rephrase my question
I don't want to pass the parent script's name to the child as parameter

If a calls b, then b should be able to tell how 'b' was called (including parameters passed to b) and how 'a' was called (including parameters)

Code:
cat a.sh
{
b.sh p1 p2 p3
}

cat b.sh
{
echo "i was called ...."
echo "my parent was called ...."
}

If i run:
a.sh a b c
the output should be:
i was called b.sh p1 p2 p3
my parent was called a.sh a b c

Thanks,
-srinivas y.

Moderator's Comments:
Mod Comment Please use code tags, ty
# 6  
Old 08-10-2010
b.sh
Code:
echo "i was called $0 $@"
echo "my parent was called $(cat /proc/$PPID/cmdline)"

# 7  
Old 08-10-2010
Code:
cat a.sh
{
b.sh p1 p2 p3
echo "my parent was called $0 $*"
}

cat b.sh
{
echo "i was called $0 $*"
}

i think this will do what you are looking for...
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

Get parent script name

Hi, my question is similar to my earlier post from 2009 which is Closed now https://www.unix.com/shell-programming-scripting/141945-get-current-parent-script-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... (1 Reply)
Discussion started by: ysrini
1 Replies

3. 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

4. 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

5. 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

6. Solaris

shell-init: could not get current directory: getcwd: cannot access parent directories

Hello root@ne-ocadev-1:/root/scripts>su espos -c find /a35vol100/ESPOS/oracle/db/9.2.0/oradata/ESPOS/archive -type f -atime +10 -exec ls {} shell-init: could not get current directory: getcwd: cannot access parent directories: Permission denied find: insufficient number of... (6 Replies)
Discussion started by: babu.knb
6 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