Need help with running Python file with GDB. Can someone help?

I can't run .py file the code of which is below. When you run gives it can't find gdb, and when run from gdb crashes another error. I already 2 days do not, how to solve the problem I do not know.

Can someone suggest how to start ???

Thank you very much.

#!gdb
import sys
import gdb
import os
os.system("echo resetFile > eip.txt")
number_restarts = 100
gdb.execute("set pagination off")
os.system("/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/rex-bin_tools-0.1.4/bin/msfelfscan -j esp ./crossfire > jmpSearch.txt")
def on_stop(sig):
 global number_restarts
 if isinstance(sig, gdb.SignalEvent):
 if (number_restarts > 0):
 os.system("rm eip.txt")
 gdb.execute("set confirm off")
 gdb.execute("set logging file eip.txt")
 gdb.execute("set logging on")
 gdb.execute("set logging overwrite on")
 gdb.execute("info registers eip")
 gdb.execute("set logging off")
 gdb.execute("set logging file badchars.txt")
 gdb.execute("set logging on")
 gdb.execute("x/500xw $esp")
 gdb.execute("set logging overwrite off")
 gdb.execute("set logging off")
gdb.execute("kill")
gdb.execute("run")
gdb.events.stop.connect (on_stop)
gdb.execute("run")
March 23rd 20 at 18:48
1 answer
March 23rd 20 at 18:50
To import the gdb module is possible only when the script is run in gdb.

Find more questions by tags GDBPython