#!/usr/bin/env python#encoding:utf-8import osimport sysimport timeimport subprocessclass myclass: print ' \033[32;1m############### ########################################################### #JAVA module: # feinnoopen_01 media_ims_01 mop_ims_download_01 osp_ims_01 Ippbx_ims_01 # mop_ims_01 mop_ims_download_01 msms_gw_01 portal_ims_01 sso_ims_01 # #C module: # ap cagw dbproxy egm ft gd gm im logserver msrp msrpgw ps robot sbc # soap soap_proxy ss stg ###################################### ###################################### \033[0m "" def __init__ (self): self.name=sys.argv[1] self.file= sys.argv[0] self.modstat = "ps -ef| grep -v grep|grep -v %s|grep %s|awk ' {print $2} ' " % (Self.file, Self.name) self.modname= "kill -9 ' PS -ef|grep -v grep|grep -v %s|grep %s|awk ' {print $2} ' " % (self.file,self.name) self.start= "/eut/internal/webapp/%s/bin/startup.sh;tail -f /eut/ Internal/webapp/%s/logs/catalina.out " % (self.name,self.name) self.cache= "rm -rf /eut/internal/webapp/%s/work/catalina/* " % (Self.name) self.cmodstat = "ps -ef|grep -ev ' grep|supervise ' |grep -v %s|grep -w %s_01|awk ' {print $2} ' " % (self.file,self.name) self.cmodname= "kill -9 ' ps -ef|grep -ev ' grep|supervise ' |grep -v %s|grep -w %s_01|awk ' {print $2} ' " % (self.file,self.name) &nbSp; self.cstart= "cd /eut/internal/pgm/%s/%s_01;nohup ./bin/%s_01 &" % ( Self.name,self.name,self.name) self.jlist=[" Feinnoopen_01 ", " media_ims_01 ", " mop_ims_download_01 ", " osp_ims_01 ", " ippbx_ims_01 ", "Mop_ims_01", "mop_ims_download_01", "msms_gw_01", "portal_ims_01", "sso_ims_01"] self.clist=["AP", "CAGW", "Dbproxy", "EGM ", " FT ", " GD ", " GM ", " im ", " logserver ", " MSRP ", " MSRPGW ", " PS ", " Robot ", " SBC ", " soap ", " Soap_proxy ", " ss ", " STG "] self.pid= "ps -ef|grep -ev ' grep|supervise ' |grep -v %s|grep -w %s_01 " % (self.file,self.name) self.jpid= "ps -ef|grep -v grep|grep -v %s|grep %s " % (self.file,self.name) def stat (self): return Os.popen (Self.modstat). ReadLines () def run (self): subprocess.call (self.start, shell=true) def clear (self): subprocess.call (self.cache, shell=true) def kill (self): subprocess.call ( Self.modname, shell=true) def cstat (self): return os.popen (Self.cmodstat). ReadLines () Def crun (self): subprocess.call (Self.cstart, shell=true) def ckill (self): subprocess.call (self.cmodname, shell=true) if _ _name__== "__main__" : try: p= MyClass () #print p.clist if p.name in p.jlist: print "= = =========== " print p.name print "=============" result= P.stat () if len (Result) == 0: print "\033[32;1m%s module does not start \033[0m" %p.name print "\033[32;1m start clearing cache \033[0m" p.clear () time.sleep (2) print "\033[32;1m boot module%s \033[0m" %p.name p.run () else: print "\033[32;1m Stop% S module \033[0m " %p.name P.kill () print "\033[32;1m start clearing cache \033[0m" p.clear () time.sleep (2) print "\033[32;1m start%s module \033[0m" %p.name p.run () elif p.name in p.clist: print "============" print p.name print "============" cresult= P.cstat () if len (Cresult) == 0: print "\033[32;1m%s module does not start \033[0m" %p.name p.crun () else: print "\033[32;1m%s module process exists \033[0m" %p.name #time. Sleep (1) print "\033[32;1m Kill process%s \033[0m" %p.name p.ckill () # time.sleep (2) print "\033[32;1m Start the process%s \033[ 0m " %p.name p.crun () time.sleep (1) print "\033[32;1m process%s started, list process id \033[0m" %p.name os.system (p.pid) else: print "\033[31;1m%s does not exist, brother please refer to the list input module name \033[0m" %p.name except KeyboardInterrupt: print "\033[31;1m exit log Monitor!!! \033[0m " print " \033[32;1m list%s process: \033[0m " %p.name os.system (p.jpid) except: print "\033[31;1m Please enter your module: \033[0m"
This article from "Chocolee" blog, declined reprint!
Python Learning Class Script--reference