Created
February 5, 2015 10:14
-
-
Save upa/0f4aa6a3928ec054e0a2 to your computer and use it in GitHub Desktop.
to get command ouput from ns-3-dce sim node stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# cgrep, dce cmdline grep | |
import re | |
import os | |
import sys | |
e_flag = False | |
s_flag = True | |
def cgrep (files, cmdline) : | |
plist = os.listdir (files + "/var/log") | |
for p in plist : | |
if not re.match (r'\d+', p) : | |
continue | |
cmdpath = files + "/var/log/" + p + "/cmdline" | |
cmd = open (cmdpath, 'r').read () | |
cmd = cmd.strip () | |
if re.search (cmdline, cmd) : | |
if e_flag : | |
outpath = files + "/var/log/" + p + "/stderr" | |
else : | |
outpath = files + "/var/log/" + p + "/stdout" | |
print "COMMAND: " + cmdpath + "\t" + cmd | |
print "OUTPUT : " + outpath | |
print open (outpath, 'r').read (), | |
def main () : | |
cmdline = sys.argv.pop () | |
for files in sys.argv : | |
cgrep (files, cmdline) | |
# remove cgre.py | |
sys.argv.pop (0) | |
if sys.argv[len(sys.argv) - 1] == "-e" : | |
e_flag = True | |
sys.argv.pop () | |
if sys.argv[len(sys.argv) - 1] == "-s" : | |
e_flag = False | |
s_flag = True | |
sys.argv.pop () | |
main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment