If I have a script, lets call it "scr.sh" And I call it from another language e.g Python Is there a way to get the traceback of the functions and files back to the Python language.

How I think it could possibly work: the scr.sh

echo "something"
echo `get_traceback` > "/tmp/traceback" 
echo "something else

And a python script "scr2.py"

if __name__ == '__main__'

def call_func(self):
    import subprocess
    print "some"
    print "thing"

Can I get the traceback the from the bash script back to the python script? I'd expect that if it exists it would look like this:

file /tmp/scr2.py , line 2 in function "main",
file /tmp/scr2.py , line 7 in function "call_func", 
bash file /tmp/scr.sh, line 2 
  • does bash -x scr.sh help? – glenn jackman Nov 14 '19 at 15:50
  • No, this is going to get the trace of the bash file commands. I don't need that. I ask if it is possible to get the trace back to the originating caller of the script. – Kostadin Krushkov Nov 15 '19 at 6:37
  • 1
    You'd have to generate the python part of the traceback before calling the bash script, and you'll have to make it available to bash (using the environment would be simplest) – glenn jackman Nov 15 '19 at 12:38
  • Yeah, that's what I was hoping to not have to do. The problem is that the bash script could be called from a number of places, and I need to find out from where exactly. Thanks anyway – Kostadin Krushkov Nov 15 '19 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.