- 论坛徽章:
- 0
|
本帖最后由 cgiyan 于 2016-05-05 10:12 编辑
我修改了我的测试脚本,但是运行报错,麻烦高手给看看,谢谢!- [code]#!/usr/bin/env python
- #coding=utf-8
- #vim: tabstop=4 shiftwidth=4 softtabstop=4
- import os
- import sys
- import time
- import threading
- import shlex
- import signal
- from subprocess import Popen, PIPE
- i = 0
- while True:
- i = i + 1
- class mythread(threading.Thread):
- def _init_(self,num):
- threading.Thread.__init__(self)
- self.num = num
- def run(self):
- self.num
- print threading.currentThread().getName()
- DIR=sys.argv[1]
- os.environ['ORACLE_HOME'] = "%s/Middleware/Oracle_IDM" % DIR
- print(os.environ['ORACLE_HOME'])
- from commands import getoutput
- result = getoutput( '%s/Middleware/Oracle_IDM/bin/ldapsearch -a always -D cn=orcladmin -w welcome1 -p 3060 -b "" -s sub "objectclass=*" orcldirectoryversion ou=Groups Privilege, cn=OperationURLs,
- cn=DAS,cn=Products,cn=OracleContext,dc=cn,dc=oracle,dc=com' % DIR)
- print result
- print i
- def cmd_run(cmd, timeout=60):
- t_beginning = int(time.time())
- cmdargs = shlex.split(cmd)
- p = Popen(cmdargs, stdout=PIPE, stderr=PIPE, preexec_fn=os.setsid)
- if p.poll() is not None:
- return
- if int(time.time()) - t_beginning >= timeout:
- os.killpg(p.pid, signal.SIGTERM)
- raise Exception(cmd, timeout)
- return p.returncode
- if __name__ == "__main__":
- t_beginning = int(time.time())
- try:
- while True:
- cmd_run(sys.argv[1])
- if int(time.time()) - t_beginning >= 10:
- break
- except IndexError as e:
- print e
- 运行报错:
- python ldap2.py /u03
- File "ldap2.py", line 57
- except IndexError as e:
- ^
- SyntaxError: invalid syntax
复制代码 [/code]
|
|