def back(self, savePath, parentPath, needBack): ''' savePath:备份文件保存的路径 parentPath:需要备份的父路径 needBack:需要备份的父目录 ''' tr = ExecUtil.execCommand(" tar czvf " + savePath + " -C " + parentPath + " " + needBack)
def yumInstall(self): child = pexpect.spawnu('yum groupinstall " NFS file server"') child.expect('(?i)Is this ok [y/N]:') child.sendline('y') child.expect('Complete!') child.close() self.writeConfig() ExecUtil.execCommand("/etc/init.d/rpcbind start ") ExecUtil.execCommand("/etc/init.d/nfs start") ExecUtil.execCommand("chkconfig nfs on") ExecUtil.execCommand("chkconfig rpcbind on")
def initSSHKey(self): home = ExecUtil.execCommand("echo ~")[1] if not os.path.exists(home + "/.ssh/id_rsa"): child = pexpect.spawnu('ssh-keygen') child.expect('(?i)(/root/.ssh/id_rsa):') child.sendline('\r') child.expect('(?i)Enter passphrase (empty for no passphrase):') child.sendline('\r') child.expect('(?i)Enter same passphrase again:') child.sendline('\r') child.expect('(?i)+-----------------+') child.close()
def downloadFile(self,downloadPath): filename=os.path.basename(downloadPath) return ExecUtil.execCommand("wget -O " + downloadPath + " " + Config.softServer+filename)
def make(self): tar_rt = ExecUtil.execCommand("tar zxvf " + self.downloadSavePath + " -C " + self.installPath)
def writeConfig(self): f = open("/etc/profile", 'a') f.write('export MAVEN_HOME=' + self.installPath + "/maven") f.write("export PATH=$MAVEN_HOME/bin:$PATH") f.close() source_rt = ExecUtil.execCommand("source /etc/profile")
def downloadTar(self): down_rt = ExecUtil.execCommand("wget -O " + self.downloadSavePath + " " + self.downloadPath)
def execCmd(self, cmd): return ExecUtil.execCommand(cmd)
info.append(install) except Exception , e: install=self.getInfo("yum install mysql*",False,"yum install mysql* false") info.append(install) return info try: self.writeConfig() install=self.getInfo("write config",True,"write config ok") info.append(install) except Exception , e: install=self.getInfo("write config",False,"write config false") info.append(install) return info rt=ExecUtil.execCommand("service mysqld restart") if rt[0]==0: install=self.getInfo("service mysqld restart",True,rt[1]) info.append(install) else: install=self.getInfo("service mysqld restart",False,rt[1]) info.append(install) return info rt=ExecUtil.execCommand("mysqladmin -u root password " + Config.mysqlRoot) if rt[0]==0: install=self.getInfo("mysqladmin -u root password "+Config.mysqlRoot,True,rt[1]) info.append(install) else: install=self.getInfo("mysqladmin -u root password "+Config.mysqlRoot,False,rt[1]) info.append(install)
info.append(install) except Exception, e: install = self.getInfo("yum install mysql*", False, "yum install mysql* false") info.append(install) return info try: self.writeConfig() install = self.getInfo("write config", True, "write config ok") info.append(install) except Exception, e: install = self.getInfo("write config", False, "write config false") info.append(install) return info rt = ExecUtil.execCommand("service mysqld restart") if rt[0] == 0: install = self.getInfo("service mysqld restart", True, rt[1]) info.append(install) else: install = self.getInfo("service mysqld restart", False, rt[1]) info.append(install) return info rt = ExecUtil.execCommand("mysqladmin -u root password " + Config.mysqlRoot) if rt[0] == 0: install = self.getInfo( "mysqladmin -u root password " + Config.mysqlRoot, True, rt[1]) info.append(install) else:
def back(self, user, pwd, db, savePath): ExecUtil.execCommand(" mysqldump -u" + user + " -p" + pwd + " -B --skip-lock-tables " + db + " |gzip > " + savePath + "/" + db + "`/bin/date +%F`.back.gz")
def back(self, user, pwd, db, savePath): ExecUtil.execCommand( " mysqldump -u" + user + " -p" + pwd + " -B --skip-lock-tables " + db + " |gzip > " + savePath + "/" + db + "`/bin/date +%F`.back.gz")
def downloadFile(self, downloadPath): filename = os.path.basename(downloadPath) return ExecUtil.execCommand("wget -O " + downloadPath + " " + Config.softServer + filename)