-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
23 lines (19 loc) · 714 Bytes
/
helpers.py
File metadata and controls
23 lines (19 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/python3
import subprocess
import sys
# ssh into instance and perform command
def ssh(key, dns, cmd):
ssh = 'ssh -o StrictHostKeyChecking=no -i ' + key + '.pem ec2-user@' + dns + ' \'' + cmd + '\''
try:
subprocess.run(ssh, shell=True)
except Exception as e:
print ('Error while connecting to host:', str(e))
sys.exit(1)
# copy files and folders to a given destination
def scp(key, dns, file, dest):
cmd = 'scp -o StrictHostKeyChecking=no -r -i ' + key + '.pem ' + file + ' ec2-user@' + dns + ':' + dest
try:
subprocess.run(cmd, shell=True)
except Exception as e:
print ('Error while connecting to host:', str(e))
sys.exit(1)