I need something like a stacktrace in bash, is that possible?
A script is misbehaving. I need to know who calls that script, and who calls the calling script, and so on, only by modifying the misbehaving script.
What do you say?
I need something like a stacktrace in bash, is that possible?
A script is misbehaving. I need to know who calls that script, and who calls the calling script, and so on, only by modifying the misbehaving script.
What do you say?
If you can edit the script itself, simply put a:
ps -ef >/tmp/bash_stack_trace.$$
in it, where the problem is occurring.
This will create a number of files in you tmp
directory that show the entire process list at the time it happened.
You can work out which process called which other process by examining the PID and PPID columns.
Keep an eye on the files, you'll get one per failing process so they may have to be managed.
You can automate the analysis of the process "stack trace" using a bit of awk/perl trickery.
adding pstree -p -u `whoami` >>output in your script will probably get you the information you need.
~$ help caller
caller: caller [EXPR]
Returns the context of the current subroutine call.
Without EXPR, returns "$line $filename". With EXPR,
returns "$line $subroutine $filename"; this extra information
can be used to provide a stack trace.
The value of EXPR indicates how many call frames to go back before the
current one; the top frame is frame 0.