- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to get the name of the calling script or b...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 04:11 AM - edited 02-24-2017 04:17 AM
02-24-2017 04:11 AM - edited 02-24-2017 04:17 AM
How to get the name of the calling script or binary from a ksh script ?
Hi,
How to use $PPID value to get the name of the parent process calling my script.
I tried this:
parent=$(ps -f -p $PPID | tail -1 | awk '{print $NF}')
echo $parent
but output is not efficient.
-ksh
Any ideas ?
Kind regards, Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 04:56 AM
02-24-2017 04:56 AM
Re: How to get the name of the calling script or binary from a ksh script ?
> How to use $PPID value to get the name of the parent process calling
> my script.
Define "name of process". Does a UNIX process have a name? On VMS,
a process does have a name. For example:
alp $ show system /process = bat*
OpenVMS V8.4 on node ALP 24-FEB-2017 06:42:43.34 Uptime 86 06:36:52
Pid Process Name State Pri I/O CPU Page flts Pages
2020ECCD BATCH_590 LEF 5 189 0 00:00:00.14 182 138 B
But, on VMS, it's harder to get the name of the command (program with
arguments) being run in a process, like UNIX "ps" output.
> but output is not efficient.
I don't understand. What, exactly, is the problem?
Why do you care? What, exactly, is the problem which you are trying
to solve?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 05:20 AM
02-24-2017 05:20 AM
Re: How to get the name of the calling script or binary from a ksh script ?
Hi,
Thanks. I have scripts calling other scripts.I want to know what is the parent script name.
example:
aa.ksh calls bb.ksh
zz.ksh calls bb.ksh
When bb.ksh is running, is there a way to give the name of script doing the call ?
Kind regards,
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 05:56 AM
02-24-2017 05:56 AM
Re: How to get the name of the calling script or binary from a ksh script ?
2 things to do here
1. if your scripts are all ksh scripts make sure the first line of all the scripts is
#!/usr/bin/ksh
2. Try using the following code instead:
UNIX95= ps -p $PPID -o args=
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 05:59 AM
02-24-2017 05:59 AM
Re: How to get the name of the calling script or binary from a ksh script ?
> When bb.ksh is running, is there a way to give the name of script
> doing the call ?
_Which_ script doing _which_ call? Doesn't your "ps" command do
that? I'm confused.
Or do you see the problem with your "ps" command if a script has
command-line arguments (as in: "bb.sh x y z")?
The easy way to do this might be to have the top-level script set
some environment variable, which any/every sub-process can see.
(Depending on exactly what you really want, of course, which is still
unclear to me.)
> aa.ksh calls bb.ksh
> zz.ksh calls bb.ksh
And what output do you want in each case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 07:38 AM
02-24-2017 07:38 AM
Re: How to get the name of the calling script or binary from a ksh script ?
Hi
> aa.ksh calls bb.ksh
output from bb.ksh will say: aa.ksh has called me
> zz.ksh calls bb.ksh
output from bb.ksh will say: zz.ksh has called me
Kind regards, Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 07:41 AM
02-24-2017 07:41 AM
Re: How to get the name of the calling script or binary from a ksh script ?
Hi,
I give a Kudo but it seems not working
...
delphix:/tmp#cat bb.ksh
#!/usr/bin/ksh
parent=`ps -p $PPID -o args=`
echo $parent
UNIX95= ps -p $PPID -o args=
echo $UNIX95
delphix:/tmp#
delphix:/tmp#cat aa.ksh
./bb.ksh
...
execution:
delphix:/tmp#./aa.ksh
-ksh
-ksh
Kind regards,
Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2017 10:25 PM - edited 02-26-2017 10:35 PM
02-26-2017 10:25 PM - edited 02-26-2017 10:35 PM
Re: How to get the name of the calling script or binary from a ksh script ?
> Define "name of process". Does a UNIX process have a name?
The basename of the executable is as good as any.
>parent=`ps -p $PPID -o args=`
The "proper" syntax is:
parent=$(UNIX95=EXTENDED_PS ps -p $PPID -oargs=)
If the caller is a shell, you'll see the name of the shell then the script and args:
/usr/bin/ksh ./yyyy.sh
If not a shell, then -ocomm= would be good enough.
>echo $UNIX95
This is useless since the variable is only set for that process. Also when you are echoing a bunch of things, it helps to have a title:
echo "UNIX95: $UNIX95"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2017 01:43 AM
03-01-2017 01:43 AM
Re: How to get the name of the calling script or binary from a ksh script ?
It does not work:
R018366[root]/tmp # cat aa.ksh
./bb.ksh
SR018366[root]/tmp # cat bb.ksh
parent=$(UNIX95=EXTENDED_PS ps -p $PPID -oargs=)
echo $parent
echo $UNIX95
parent=$(UNIX95=EXTENDED_PS ps -p $PPID -ocomm=)
echo $parent
echo $UNIX95
I run
./aa.ksh
Output
SR018366[root]/tmp # ./aa.ksh
-ksh
ksh
Not better !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2017 10:41 PM
03-11-2017 10:41 PM
Re: How to get the name of the calling script or binary from a ksh script ?
> It does not work:
You didn't do what Duncan said and I always do. You MUST start each script with the name of the interpreter:
#!/usr/bin/ksh
Not sure why it makes a difference but the shell doesn't know the name of the script if you forget it.
> echo $UNIX95
As I said, this does nothing, remove it.
>-ksh
>ksh
These are the actual names of the parent process. The login and subshell ksh.