def _verUserConn(sn,un,pw): cmd='%s\plink.exe -ssh %s@%s -pw %s -batch pwd' % (mg.binDir,un, sn,pw) rc,rcmd = process.runSync(cmd,mg.logger) mg.logger.debug("cmd = %s rc = %s " % (cmd,rc)) if rc == 0 and len(rcmd) > 1 : return 0 else: return -2
def connRemServ(s,un): rc = -1 if un.strip() == '': return -2 if isinstance(s, str) and s.isdigit(): sid = int(s) elif isinstance(s, int) : sid = s else: return mm.INV_ID_DTYPE if not mg.serv_lkup.has_key(sid): return mm.INV_SRV_KEY sn = mg.serv_lkup[sid] pwd = _getRemConnCred(sn,un) if pwd.strip() != '': rc = _verUserConn(sn,un,pwd) # un/pwd OK lets go ahead and invoke the ssh command. if rc == 0: cmd = '%s\putty.exe -ssh %s@%s -pw %s' % (mg.binDir, un, sn, pwd) mg.logger.debug("cmd = %s " % cmd) rc,rm = process.runSync(cmd,mg.logger) return 0 return rc
def pingDB(self) : rc = 1 cmd = 'tnsping %s ' % self.ib.db_name rc, msg = p.runSync(cmd, self.logger) if rc == 0 : rc = su.findStr(msg,'OK ') return rc
def _gss_infoAll_win32(): # Invoke gss command. ggsci < infall.datggsci < infall.dat bfn = "chk_all_proc" # By convention will add .bat termination. MANDATORY gss_cmd = "%s/%s.bat" % (ib.rpath, bfn) log.debug("gss_cmd = %s" % gss_cmd) rc, rmsg = proc.runSync(gss_cmd, log) if rc != 0: log.error("cmd %s rc = %s -> msg= %s" % (gss_cmd, rc, rmsg)) return rmsg
def _delNZRows(args,table_name): cmd = [" nzsql -host %s -db %s -u %s -pw %s -c 'delete from %s..%s'" % (args['nz_db_host'], args['nz_db_env'], args['nz_db_user'], args['nz_db_pwd'], args['nz_db_env'], table_name)] rc,rmsg = proc.runSync(cmd, log) if rc == 0 : log.debug ('cmd %s -> msg= %s' % (cmd,rmsg) ) else : log.error('cmd %s rc = %s -> msg= %s' % (cmd,rc,rmsg)) return rc
def _getNZCnt(args,table_name): # Get number of records in NZ table cmd = [" nzsql -host %s -db %s -u %s -pw %s -c 'select count(1) from %s..%s' |head -3|tail -1" %(args['nz_db_host'], args['nz_db_env'], args['nz_db_user'], args['nz_db_pwd'], args['nz_db_env'], table_name)] rc,rmsg = proc.runSync(cmd, log) if rc == 0 : log.debug ('cmd %s -> msg= %s' % (cmd,rmsg) ) return rmsg.strip() else : log.error('cmd %s rc = %s -> msg= %s' % (cmd,rc,rmsg)) return -1
def _getGPCnt(args,table_name): # Get number of records in GP table cmd = ["psql -h %s -p %s -U %s -d %s -c 'select count(1) from %s.%s' |head -3 |tail -1" % (args['gp_db_host'], args['gp_db_port'], args['gp_db_user'], args['gp_db_env'], args['gp_db_sche'], table_name,)] rc,rmsg = proc.runSync(cmd,log) if rc == 0 : log.debug ('cmd %s -> msg= %s' % (cmd,rmsg) ) return rmsg.strip() else : log.error('cmd %s rc = %s -> msg= %s' % (cmd,rc,rmsg)) return -1
def wFinDetail(self): # Update State File, for next run. Wkf has a final command task that wilol UPdate the file to RUN. # If cmd task does not ran we know wkf is not successful and should not start. fn = '%s/%s.state' % (self.ib.ctlDir, self.appName) dt = '%s-EXECUTING' % su.getTimeSTamp('%d%02d%02d:%02d:%02d') self.log.debug("fn = %s Updating TO ==> dt = %s" % (fn,dt)) rc = fu.updFile(fn,dt) self.log.info('Updating state returned %s' % rc) cmd = '%s/pstate.sh findetailmf EXECUTING' % self.ib.appDir p.runSync(cmd,self.log) # Start WKF execution self.ib.fld = 'Financial' self.ib.wkf = 'wkf_FIN_DETAIL' rc = pi.runWkflWait(self.ib,self.log) if rc != 0 : self.log.error('Running %s.%s rc = %s' % (self.ib.fld,self.ib.wkf,rc)) else : self.log.info('Running %s.%s rc = %s' % (self.ib.fld,self.ib.wkf,rc)) return rc
def _procFiles(self,filestoProc): rc = 0; r = 1 for ef in filestoProc: cmd = '%s/ArchivoBatch.exe %s' % (self.ib.scriptDir,ef) r,rmsg = p.runSync(cmd, self.log) ftn = fu.getFileBaseName(ef) self.log.debug('r = %s cmd = %s ftn = %s' % (r,cmd,ftn)) if r != 0 and r != 95: tgt = '%s/%s.%s' % (self.ib.badDir,ftn,self.ts) self.log.error ('r = %s cmd = %s rmsg=%s' % (r,cmd,rmsg)) rc+=r else : self.log.info ('r = %s cmd = %s rmsg=%s' % (r,cmd,rmsg)) tgt = '%s/%s.%s' % (self.ib.archDir,ftn,self.ts) r = fu.moveFile(ef, tgt) if r == 0 : self.log.info( 'mv %s to %s' % (ef,tgt)) else : self.log.error('mv %s to %s r = %s ' % (ef,tgt,r)) return rc
def _insNZLoad(self,val,seqid): ldata = [] for s,u,p,d in val : ldata.append("%s,%s,%s,%s\n" % (s,u,p,d )) data = ''.join(ldata) # Create CSV file fn = '%s/%s.csv' % (self.ib.dataDir,seqid) fl = '%s/tis_fb_carr_pmpt_imprt_dtl_%s.%s.nzlog' % (self.ib.dataDir,seqid,self.ib.db) bf = '%s/tis_fb_carr_pmpt_imprt_dtl_%s.%s.nzbad' % (self.ib.dataDir,seqid,self.ib.db) rc = fu.createFile(fn, data) self.log.debug('File Creation %s/%s.csv rc = %s' % (d,seqid,rc)) if rc != 0 : self.log.error('File Creation %s/%s.csv rc = %s' % (d,seqid,rc)) return rc # Invoke nzload command nz_cmd = "%s/nzload -host %s -u %s -pw %s -db %s -t tis_fb_carr_pmpt_imprt_dtl -delim '%s' -df %s -lf %s -bf %s" % (self.ib.nzbin, self.ib.dbserver, self.ib.user, self.ib.pwd, self.ib.db, self.ib.delim, fn,fl,bf) self.log.debug('nz_cmd = %s' % nz_cmd) rc,rmsg = proc.runSync(nz_cmd,self.log) if rc != 0 : self.log.error('cmd %s rc = %s -> msg= %s' % (nz_cmd,rc,rmsg)) return rc # Delete csv file (based on option) if self.delCSVFileFlg is True: r = fu.delFile(fn) self.log.debug('Deleting %s rc = %s ' % (fn,r)) if r != 0 : self.log.error('Cannot Delete %s ' % fn ) return rc
def _execCmd(self,c): cmd = '%s %s' % (mg.infasetup, c) self.logger.debug("cmd = %s" % cmd) #return 0, "PLEASE IMPLEMENT FX" return p.runSync(cmd,self.logger)
def _execCmd(self,c): cmd = '%s %s' % (mg.infasrv, c) self.logger.debug("cmd = %s" % cmd) return p.runSync(cmd,self.logger)
def _metaBkup(): rc,rm = ps.runSync(bc.SASBkupCmd, log) return rc