Advertisement
Guest User

DeBash - debugging Shell Scripts

a guest
Feb 26th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import sys
  4.  
  5. filename = "FILE0"
  6. funcname = "FUNC0"
  7. start_writren = True
  8.  
  9.  
  10. if len(sys.argv) < 2:
  11.     print "ERROR: NO FILENAME DIVEN!"
  12. else:
  13.     inputFile = open( sys.argv[1], "r" )
  14.     filename = sys.argv[1]
  15.     sourceArray = []
  16.     for line in inputFile:
  17.         sourceArray.append( line )
  18.     print "EXEC: Read done."       
  19.  
  20. # print sourceArray
  21.     if (len(sys.argv) == 3):
  22.         destFile = open(sys.argv[2], "w")
  23.     else:  
  24.         destFile = open(sys.argv[1], "w")
  25.  
  26.     sourceArray[0] = "%s %s" % (sourceArray[0], 'echo "Entered[%s]" >> /tmp/wisc.log\n' % (filename))
  27.     for line in sourceArray:
  28.         # hard
  29.         if(line.find("()") != -1):
  30.             funcname = line[0:line.find("()")+2]
  31.             start_writren = False
  32.  
  33.  
  34.         if(line.find("{") == -1 and line.find("}") == -1):
  35.             destFile.write(line)
  36.         else:
  37.             if(line.find("{") != -1 and line.find("}") == -1 and start_writren == False): # found only for the first time{
  38.                 destFile.write(line)
  39.                 destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log\n' % (filename, funcname, "start") )
  40.                 start_writren = True
  41.             elif(line.find("{") == -1 and line.find("}") != -1 and line == '}\n' ): # found only }
  42.                 destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log\n' % (filename, funcname, "end") )
  43.                 destFile.write(line)
  44.             else:
  45.                 destFile.write(line)
  46.         #   hard done
  47.     destFile.write('echo "Exited[%s]" >> /tmp/wisc.log\n' % (filename))
  48.     print "EXEC: Write done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement