-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull2pi.py
32 lines (29 loc) · 949 Bytes
/
pull2pi.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
#ingest
import paramiko, os, time, shutil
##### set these variables
#ssh_ip = '172.16.42.1'
#ssh_user = 'myUser'
#ssh_pw = 'myPw'
#####
def move2newlogs():
for incoming in os.walk('/home/data/incoming'):
for logfile in incoming[2]:
newname = '/home/data/newlogs/' + time.strftime('%Y%m%d_%H%M%S') + logfile
oldname = incoming[0] + '/' + logfile
shutil.move(oldname, newname)
time.sleep(1)
while 1 == 1:
time.sleep(1)
try:
ssh = paramiko.SSHClient()
#temporary - add host to ~/.ssh/known_hosts
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ssh_ip,username=ssh_user,password=ssh_pw)
ftp = ssh.open_sftp()
ftp.get('/sd/logs/pineap.log', '/home/data/incoming/pineap.log')
ftp.close()
ssh.exec_command('rm /sd/logs/pineap.log')
ssh.close()
move2newlogs()
except:
pass