| author: | Guannan Ma |
|---|---|
| create_date: | 2013 |
| last_date: | 2014 |
| descrition: | Guannan just made a wraper out of pexpect. The original copyright belongs to the author of pexpect module. See it at http://pexpect.sourceforge.net/pexpect.html |
拷贝hostname, src目录到本地的dst目录。 采取scp -r的模式。
| Returns: | dict.有 ‘exitstatus’ ‘remote_exitstatus’ ‘result’ 三项输出内容 |
|---|
回返在hostname机器上执行的shell命令结果信息 历史兼容函数。 推荐使用go_ex command 有较多转义字符的,不推荐使用go,推荐使用go_witch_scp
| Returns: | 类型tuple: (ret, return_string) ret 是本机执行远程命令的返回值 return_string 是远程执行这条shell的输出值 |
|---|
回返在hostname机器上执行的shell命令结果信息, 相比go而言, 回返信息更丰富,且按照dict方式回返. command 有较多转义字符的,不推荐使用go,推荐使用go_witch_scp
| Returns: | dict.有 ‘exitstatus’ ‘remote_exitstatus’ ‘result’ 三项输出内容 |
|---|
回返在hostname机器上执行的shell命令结果信息, 方式是:把command 写入本机文件,然后scp到远端机器,然后到远端执行此文件 相比go_ex 和 go 而言,多了如下参数
| Parameters: |
|
|---|---|
| Returns: | dict.有 ‘exitstatus’ ‘remote_exitstatus’ ‘result’ 三项输出内容 |
| author: | Guannan Ma |
|---|---|
| create_date: | 2014 |
| last_date: | 2014 |
| descrition: | shell related module |
以popen的方式执行某条shell命令, 返回os.popen(cmd) Deprecated. 不推荐使用, 推荐使用ShellExec
历史兼容函数。 不推荐使用 同execshell_withpipe_ex, 但回返信息是string. (将所有行join成一个string回返) 该函数会将stdout和stderr一同回返。
通过ps -ef|grep -w procname$ |grep -v grep|wc -l 判断进程是否存在 相关函数有: cup.oper.is_proc_exist(path, name)
历史兼容函数。 执行某条shell命令,回返执行stdout的结果行(list). Deprecated. 不推荐使用, 推荐使用ShellExec.
历史兼容函数。 同execshell_withpipe_ex, 但回返信息是string. (将所有行join成一个string回返)
Bases: object
用来执行shell的类。 用法如下: shellexec = cup.shell.ShellExec() # timeout=None, 一直等待直到命令执行完 shellexec.run(‘/bin/ls’, timeout=None) # timeout>=0, 等待固定时间,如超时未结束terminate这个shell命令。 shellexec.run(cmd=’/bin/ls’, timeout=100)
参见类说明。
| Parameters: |
|
|---|---|
| Returns: | 一个dict, 包含’stdout’ ‘stderr’ ‘returncode’ 三个key: returncode == 0 代表执行成功, returncode 999代表执行超时
} |
E.g.
执行ls, 超时时间为1s, 超过1s会kill掉该shell进程, 然后回返returncode 999
import cup
shelltool = cup.shell.ShellExec()
print shelltool.run('/bin/ls', timeout=1)