Shell script calling shell script - List of all
Hi LQ members,
I am working on a build-test system of a set of codes. The system ( large enough ) is such that one shell script does some work and calls another shell script.. this inturn calls a third shell script and so on.. My question is : How to get the list of all such shell scripts according to the way they are called. ? More like a shell script flow tree.!! ? Ex. Code:
#./1.sh Thanks, Nikunj Bangalore, India |
Not sure how many shell scripts you’re talking about, but we do something similar where I work (shell scripts call each other like functions), to keep troubleshooting easier we add a "Echo Starting $0" to the start of every .sh, and an "Echo Exiting $0" at the end, this way we can quickly tell what is blowing up, and where we need to troubleshoot. There has been talk about having the ability add a 'debug' flag to each to enable/disable the output, but it's pretty low on the priority list.
|
Quote:
Code:
ps axfu The do-it-yourself way would be to find out the PID of the original parent, e.g. via the process name, the use ps to list all its children recursively. Here is an example bash script; give it the name(s) of the parent script(s) as parameters: Code:
#!/bin/bash Hope this helps. |
Hi Nominal,
Thanks a lot for your script. I created few sample scripts ( 1.sh --> 2.sh --> 3.sh --> 4.sh, 5.sh ) and put echo statements in them. Script 5.sh has a while infinite loop. I tried running it as Code:
[Terminal 1] I checked with below command and found nothing. Code:
#ps -ef | grep 1.sh Thanks, Nikunj |
|
Please be aware that there are some different flavors of 'ps', each with their own options and output formatting. If you are running on a non-Linux host, this will probably have an impact, especially on something like Solaris. This particularly sucks, since there really is no standard API for acquiring information about the process table, and parsing the output of ps seems to be the standard method with the likes of the OP's problem. Nominal's use of very specific format specification is probably the best defense against the schizophrenic behavior of ps.
--- rod. |
Thanks for the useful information folks. !!
|
Quote:
Also, if Code:
ps x -o pid,args | grep -e 1.sh If a process is no longer seen by ps, it is impossible to find which processes it started. (You can, however, use the Linux audit service to track program executions (exec system calls) and process creation (fork system calls), and afterwards look at the log to find out which processes spawned which. My script only takes a snapshot of the current process relationships. Quote:
I tried with these four scripts, 1.sh to 4.sh: Code:
#!/bin/sh Code:
#!/bin/sh Code:
#!/bin/sh Code:
#!/bin/sh Code:
/bin/bash ./1.sh |
All times are GMT -5. The time now is 01:03 AM. |