1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/bin/sh
# -*- python -*-
################################################################################
# This file is python 2/3 bilingual.
# The line """:" starts a comment in python and is a no-op in shell.
""":"
# Shell code to find and run a suitable python interpreter.
for cmd in python3 python python2; do
command -v > /dev/null $cmd && exec $cmd $0 "$@"
done
echo "Error: Could not find a valid python interpreter --> exiting!" >&2
exit 2
":""" # this line ends the python comment and is a no-op in shell.
################################################################################
from __future__ import print_function
import os, sys, re, time, argparse
from LMODdb import LMODdb
class CmdLineOptions(object):
""" Command line Options class """
def __init__(self):
""" Empty Ctor """
pass
def execute(self):
""" Specify command line arguments and parse the command line"""
parser = argparse.ArgumentParser()
parser.add_argument("-D", dest='debug', action="store_true", help="Debug Flag")
parser.add_argument("--confFn", dest='confFn', action="store", default="lmod_db.conf", help="Name of the database")
parser.add_argument("syslog_fn", help="Syslog file name")
args = parser.parse_args()
return args
def syshost(name):
hostA = name.split('.')
idx = 1
if (len(hostA) < 2):
idx = 0
return hostA[idx]
def main():
args = CmdLineOptions().execute()
lmod = LMODdb(args.confFn)
modulePatt = re.compile(r'.*ModuleUsageTracking:? *')
f = open(args.syslog_fn,"r")
for count, line in enumerate(f):
line = line.rstrip("\n")
dataT = dict(re.findall(r'(\S+)=(".*?"|\S+)', rest))
if (dataT.get('host') == None):
print(line)
dataT['syshost'] = syshost(dataT['host'])
if (args.debug): print("\nCall lmod.data_to_db")
lmod.data_to_db(args.debug, count, dataT, line)
f.close()
if ( __name__ == '__main__'): main()
|