-
Notifications
You must be signed in to change notification settings - Fork 2
/
ssh-commands.py
54 lines (41 loc) · 1.18 KB
/
ssh-commands.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
#!/usr/bin/python
import paramiko
import os
import datetime
import sys
HOST = 'somehost.com';
LOGIN = 'root'
PASS = 'pass'
BBUSER = 'Login'
BBPASS = 'Pass'
COMMANDS = []
if len(BBUSER) < 1:
print ("No user specified!")
sys.exit()
if len(BBPASS) < 1:
BBPASS = input("Please enter your password: ")
UP = [
{
"name" : "Conname AI",
"commands" : [" cd /home/selly/ai && hg pull https://" + BBUSER + ":" + BBPASS + "@bitbucket.org/User/sellyai && hg up -C && python3 console.py migrate && python3 console.py commands && python3 console.py self-teach && kill -9 `pgrep selly-ai-dbg`"]
}
]
for site in UP:
update = input("Want to update " + site['name'] + "[y/N]: ")
if ( len(update) == 1 and update.lower() == 'y'):
COMMANDS = COMMANDS + site['commands']
print( "Connecting through SSH" )
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(HOST, username=LOGIN, password=PASS)
print( "Ok" )
print( "-" * 40 )
for cmd in COMMANDS:
print( "Running command:", cmd )
stdin, stdout, stderr = ssh.exec_command(cmd)
stdin.flush()
response = stdout.readlines()
print( "RESPONSE:" )
print( "\n".join(response) )
print( "-" * 40 )
ssh.close()