-
Notifications
You must be signed in to change notification settings - Fork 2
/
go
executable file
·71 lines (61 loc) · 1.42 KB
/
go
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
68
69
70
71
#!/usr/bin/python
# gopy.py
import os
import json
import sys
import commands
def getRootPath():
path_info = commands.getstatusoutput('cd && pwd')
return path_info[1]
def call(data):
if data['host'] == None:
print "try to call invalid host"
return
command = 'ssh ' + data['host']
print command
if 'passwd' in data:
command = "sshpass -p \"" + data['passwd'] + "\" " + command
if 'rsa' in data:
command = command + " -i " + data['rsa']
if 'cmd' in data:
command = command + " " + data['cmd']
os.system(command)
def goTag(tag):
for v in CONFIG:
if v['tag'] == tag:
call(v)
return
tag = int(tag) - 1
if CONFIG[tag]:
call(CONFIG[tag])
return
print "%s not found" % tag
def printInfo():
i = 1
for v in CONFIG:
print "%s) %s\t%s" % (i, v['tag'], v['host'])
i = i + 1
print "q) exit"
# run
CONFIG_FILE = getRootPath() + '/.goconfig'
try:
fileObject = open(CONFIG_FILE)
all_content_text = fileObject.read()
except:
print "%s not exists" % CONFIG_FILE
exit()
finally:
fileObject.close()
CONFIG = json.loads(all_content_text)
def start():
printInfo()
tag = raw_input("Enter to go: ")
if tag == 'q' or tag == 'exit':
exit()
elif tag == '':
start()
goTag(tag)
if len(sys.argv) <= 1 :
start()
else:
goTag(sys.argv[1])