-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcssh.sh
More file actions
executable file
·52 lines (40 loc) · 1.43 KB
/
cssh.sh
File metadata and controls
executable file
·52 lines (40 loc) · 1.43 KB
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
#!/usr/local/bin/python3
import sys
import subprocess
import requests
user = "root"
instances = {
"redis": "64.52.162.153",
"auth": "64.190.90.243",
"search": "64.190.91.125",
"qa": "140.82.9.197",
"registration": "130.245.171.197",
"email-verification": "207.148.20.88",
"felk": "107.191.43.73",
"routing": "8.9.11.218"
}
if len(sys.argv) != 2 and len(sys.argv) != 4:
print("Invalid arguments. Usage: ./cssh.sh list|<hostname> [-u <user>]")
exit(1)
if sys.argv[1] == "list":
for key in instances.keys():
print("{key}: {ip}".format(key=key, ip=instances[key]))
exit(0)
if sys.argv[1] == "clear":
data = { "query": { "match_all": {} } }
indices = ["views", "answers", "questions", "users", "q-upvotes", "a-upvotes"]
for index in indices:
response = requests.post("http://admin:ferdman123@130.245.169.86:92/{index}/_delete_by_query".format(index=index), json=data)
exit(0)
hostname = sys.argv[1]
if len(sys.argv) == 4:
flag = sys.argv[2]
if flag != "-u":
print("Invalid flag, '{flag}'. Usage: ./cssh.sh list|<hostname> [-u <user>]".format(flag=flag))
exit(1)
user = sys.argv[3]
if hostname not in instances:
print("Invalid hostname. Possible hostnames: {instances}".format(instances=list(instances.keys())))
exit(1)
cmd = "ssh -i ~/.ssh/id_rsa {user}@{instance}".format(user=user, instance=instances[hostname])
subprocess.run(cmd.split())