- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Determine what called script
Operating System - Linux
1753261
Members
5228
Online
108792
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО08-04-2006 08:55 AM
тАО08-04-2006 08:55 AM
Is there a way to tell in a script whether it was called from the command line or by another script. And if it was a script, which one?
Thanks,
Steve
Thanks,
Steve
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2006 09:01 AM
тАО08-04-2006 09:01 AM
Re: Determine what called script
The easiest way is to look at the PPID (Parent Process ID) of the script. Then look for that PID. That will tell you what you want to know.
For example:
I want to know what started an instance of gpm.
gpm's PPID is 25067.
user 28888 25067 0 11:12:39 pts/0 1:08 gpm
So I look for PID 25067:
# ps -ef |grep 25067
user 25067 25065 0 11:10:45 pts/0 0:00 -sh
user 28888 25067 0 11:12:39 pts/0 1:08 gpm
You see that PID 25067 is a '-sh' process. So it was started from user's shell.
For example:
I want to know what started an instance of gpm.
gpm's PPID is 25067.
user 28888 25067 0 11:12:39 pts/0 1:08 gpm
So I look for PID 25067:
# ps -ef |grep 25067
user 25067 25065 0 11:10:45 pts/0 0:00 -sh
user 28888 25067 0 11:12:39 pts/0 1:08 gpm
You see that PID 25067 is a '-sh' process. So it was started from user's shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-04-2006 09:08 AM
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2006 01:15 PM
тАО08-06-2006 01:15 PM
Re: Determine what called script
As mentioned, use the variable $PPID which is the process's parent. However, don't use grep and ps -- you'll get erratic results. The reason is that the PPID might be 123 and grep will match 123 1234 4123 24123 in both PID and PPID as well as possible command line parameters. Use this:
ps -fp $PPID
and you'll always get the parent's details.
Bill Hassell, sysadmin
ps -fp $PPID
and you'll always get the parent's details.
Bill Hassell, sysadmin
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP