-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
67 lines (49 loc) · 1.43 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# coding=UTF-8
import fabfile
from fabric.api import *
from time import strftime
import json
import time
import os
import sys
# 读取fabfile文件的cf参数
cf = fabfile.cf
# 定义env
env.user = cf.get('test', 'localuser')
env.password = cf.get('test', 'localuser_passwd')
env.hosts = cf.get('test', 'hosts').split(',')
# 定义sudo用户参数
sudouser = cf.get('test', 'sudouser')
sudouser_passwd = cf.get('test', 'sudouser_passwd')
# 这个是将shell的输出结果传给python程序
# 应用于python需要取得某些值,在给其他地方去定义
def test1():
bbb = run("whoami", shell=False, pty=False)
print(bbb)
# 这个是忽略类似于模拟shell命令的一步一步执行的情况,根据提示信息,输出相对应的值
# 应用于添加用户、hadoop第一次启动,等需要根据提示信息填值的情况
def test2():
with settings(prompts={
'Are you sure you want to continue connecting (yes/no)? ': 'yes'
}):
run('whoami')
# 这个貌似是碰到错误继续执行?
def test3():
with settings(warn_only=True):
run("whoami")
def test4():
aaa = run('pwd')
print(aaa[:-1])
def test5():
a = b = 3
print(a, b)
def test6():
try:
aaa = cf.get('66666', 'loc7777aluser')
except:
aaa = ''
print(aaa)
def test7():
pass
if __name__ == '__main__':
test7()