Exemplo n.º 1
0
def Read_config(file="%s/cheung/conf/cheung.conf"%HOME):
	global Servers,Useroot,Timeout,RunMode,UseKey,Deployment,ListenTime,ListenFile,ListenChar,ServersPort,ServersPassword,ServersUsername,ServersRootPassword,NoPassword,NoRootPassword,HostsGroup,HOSTSMD5,CONFMD5,sudo
	ServersPort={};ServersPassword={};ServersUsername={};ServersRootPassword={};Servers=[];HostsGroup={}
	try:
		HOSTSMD5=filemd5.main(HostsFile)
		CONFMD5=filemd5.main(ConfFile)
	except Exception,e:
		print "读取配置文件错误(%s)" % e
		sys.exit(1)
Exemplo n.º 2
0
def Read_config(file="/cheung/conf/cheung.conf"):
	global Servers,Useroot,Timeout,RunMode,UseKey,Deployment,ListenTime,ListenFile,ListenChar,ServersPort,ServersPassword,ServersUsername,ServersRootPassword,NoPassword,NoRootPassword,HostsGroup,HOSTSMD5,CONFMD5
	ServersPort={};ServersPassword={};ServersUsername={};ServersRootPassword={};Servers=[];HostsGroup={}
	try:
		HOSTSMD5=filemd5.main(HostsFile)
		CONFMD5=filemd5.main(ConfFile)
	except Exception,e:
		print "读取配置文件错误(%s)" % e
		sys.exit(1)
Exemplo n.º 3
0
def Excute_cmd():
	global All_Servers_num_all,All_Servers_num,All_Servers_num_Succ,Done_Status,Logcmd,ListenLog,Global_start_time,PWD,FailIP,ScriptFilePath,CONFMD5,HOSTSMD5
	Done_Status='end'
	All_Servers_num    =0
	All_Servers_num_Succ=0
	UseLocalScript='N' #
	PWD='~'
	IS_PWD=False
	UseSystem=False
	Servers_T=Servers
	FailIP=[];LastCMD=[]
	if Useroot=="Y":
		CmdPrompt="CheungSSH root"
	elif sudo:
		CmdPrompt="CheungSSH sudo"
	else:
		CmdPrompt="CheungSSH"
	while True:
		All_Servers_num_all=len(Servers_T)
		OPTime=time.strftime('%Y%m%d%H%M%S',time.localtime())
		Askreboot="no"
		for t in threading.enumerate():
			if t is threading.currentThread():
				continue
			else:
				t.join()
		#Threading Done
		try:
			if IS_PWD:
				ShowPWD=re.sub(";$","",PWD.split()[1])
				ShowPWD=re.sub("/{2,}","/",ShowPWD)
				ShowPWD=re.sub("cd *","",ShowPWD)
			else:
				ShowPWD=re.sub(";$|cd *","",PWD)
		except Exception,e:
			ShowPWD=PWD
		cmd=raw_input("%s %s>>>> " % (CmdPrompt,ShowPWD  ))
		if HOSTSMD5!=filemd5.main(HostsFile):
			Askreboot=raw_input("Hosts配置文件发生变化,重启程序[%s]才能生效 (yes/no)? " %sys.argv[0])
			HOSTSMD5=filemd5.main(HostsFile)
		elif CONFMD5!=filemd5.main(ConfFile):
			Askreboot=raw_input("conf配置文件发生变化,重启程序[%s]才能生效 (yes/no)? " %sys.argv[0])
			CONFMD5=filemd5.main(ConfFile)
		if re.search("^ *[Yy]([Ee][Ss])? *$",Askreboot):
			sys.exit()
		cmd=re.sub('^ *ll *','ls -l ',cmd)
		cmd=re.sub("^ *top","top  -b -d 1 -n 1 ",cmd)
		cmd=re.sub("^ *ping","ping  -c 4 ",cmd)
		try:
			if not IS_PWD:
				if re.search("^ *cd.*",cmd):
					try:
						cmd.split()[1]
					except IndexError:
						PWD="cd ~;"
						continue
					PWD=re.search("^ *cd.*",cmd).group() +";"
					IS_PWD=True
					if not os.path.isfile("%s/cheung/flag/.NoAsk"%HOME):
						AskNotice=raw_input("\033[1;33m注意: 请您确保切换的路径[%s]在远程服务器上是存在的,否则切换路径没有任何意义,您清楚了吗?\033[0m(yes/no) " % (re.sub("^ *cd *|;","",PWD)))
						if re.search("[Yy]([Ee][Ss])?",AskNotice):
							AskCancel=raw_input("是否取消以上提示?(yes/no) ")
							if re.search("[Yy]([Ee][Ss])?",AskCancel):
								try:
									os.mknod("%s/cheung/flag/.NoAsk"%HOME)
									os.system("chmod 777 %s/cheung/flag/.NoAsk"%HOME)
									print "已取消提醒"
								except Exception,e:
									print "抱歉,不能取消提示(%s)" %e
						else:
							print "如果您对以上提示不清楚,那么那您可以在远程服务器上手动%s 那一定会报错的,所以请确保[%s]有效!" % (re.sub(";","",PWD),re.sub("^ *cd *|;","",PWD))
							sys.exit()



					continue
				else:
					if PWD=="~":
						PWD="cd %s;" % PWD
			else:
Exemplo n.º 4
0
							print "取消失败 (%s)" % e
							
			try:
						
				FileFlag=EditFile +str(random.randint(999999999,999999999999))
				for a in Servers_T:
					if UseKey=='Y':
						IsEdit=GetFile.GetFile(a,ServersPort[a],ServersUsername[a],None,'Y',EditFile,FileFlag)
					else:
						IsEdit=GetFile.GetFile(a,ServersPort[a],ServersUsername[a],ServersPassword[a],'N',EditFile,FileFlag)
						
					break
				if IsEdit:
					print 'Editing...'
					ViFile="/tmp/" +os.path.basename(FileFlag)
					FileMD5=filemd5.main(ViFile)
					try:
						os.system("vi %s"%ViFile)
						if not FileMD5==filemd5.main(ViFile):
							os.system("clear")
							print "Updateing  [%s] ..." % EditFile
							#if SysVersion<2.6:
							if UseKey=='Y':
								for a in Servers_T:
									UpdateFile.UpdateFile(a,ServersPort[a],ServersUsername[a],None,'Y',ViFile,EditFile)
							else:
								for a in Servers_T:
									UpdateFile.UpdateFile(a,ServersPort[a],ServersUsername[a],ServersPassword[a],'N',ViFile,EditFile)
								
									
									
Exemplo n.º 5
0
def Excute_cmd():
	global All_Servers_num_all,All_Servers_num,All_Servers_num_Succ,Done_Status,Logcmd,ListenLog,Global_start_time,PWD,FailIP,ScriptFilePath,CONFMD5,HOSTSMD5
	Done_Status='end'
	All_Servers_num    =0
	All_Servers_num_Succ=0
	UseLocalScript='N' #
	PWD='~'
	IS_PWD=False
	UseSystem=False
	Servers_T=Servers
	FailIP=[];LastCMD=[]
	if Useroot=="Y":
		CmdPrompt="CheungSSH root"
	else:
		CmdPrompt="CheungSSH"
	while True:
		All_Servers_num_all=len(Servers_T)
		OPTime=time.strftime('%Y%m%d%H%M%S',time.localtime())
		Askreboot="no"
		if Done_Status=='end':
			try:
				if IS_PWD:
					ShowPWD=re.sub(";$","",PWD.split()[1])
					ShowPWD=re.sub("/{2,}","/",ShowPWD)
					ShowPWD=re.sub("cd *","",ShowPWD)
				else:
					ShowPWD=re.sub(";$|cd *","",PWD)
			except Exception,e:
				ShowPWD=PWD
				pass
			cmd=raw_input("%s %s>>>> " % (CmdPrompt,ShowPWD  ))
		else:
			time.sleep(0.05)
			continue
		if HOSTSMD5!=filemd5.main(HostsFile):
			Askreboot=raw_input("Hosts配置文件发生变化,重启程序[%s]才能生效 (yes/no)? " %sys.argv[0])
			HOSTSMD5=filemd5.main(HostsFile)
		elif CONFMD5!=filemd5.main(ConfFile):
			Askreboot=raw_input("conf配置文件发生变化,重启程序[%s]才能生效 (yes/no)? " %sys.argv[0])
			CONFMD5=filemd5.main(ConfFile)
		if re.search("^ *[Yy]([Ee][Ss])? *$",Askreboot):
			sys.exit()
		cmd=re.sub('^ *ll','ls -l',cmd)
		try:
			if not IS_PWD:
				if re.search("^ *cd.*",cmd):
					try:
						cmd.split()[1]
					except IndexError:
						PWD="cd ~;"
						continue
					PWD=re.search("^ *cd.*",cmd).group() +";"
					IS_PWD=True
					if not os.path.isfile("/cheung/flag/.NoAsk"):
						AskNotice=raw_input("\033[1;33m注意: 请您确保切换的路径[%s]在远程服务器上是存在的,否则切换路径没有任何意义,您清楚了吗?\033[0m(yes/no) " % (re.sub("^ *cd *|;","",PWD)))
						if re.search("[Yy]([Ee][Ss])?",AskNotice):
							AskCancel=raw_input("是否取消以上提示?(yes/no) ")
							if re.search("[Yy]([Ee][Ss])?",AskCancel):
								try:
									os.mknod("/cheung/flag/.NoAsk")
									os.system("chmod 777 /cheung/flag/.NoAsk")
									print "已取消提醒"
								except Exception,e:
									print "抱歉,不能取消提示(%s)" %e
						else:
							print "如果您对以上提示不清楚,那么那您可以在远程服务器上手动%s 那一定会报错的,所以请确保[%s]有效!" % (re.sub(";","",PWD),re.sub("^ *cd *|;","",PWD))
							sys.exit()



					continue
				else:
					if PWD=="~":
						PWD="cd %s;" % PWD
			else: