Guest User

Untitled

a guest
Aug 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. (initial ssh setup)
  2. ...
  3. data_buffer = ""
  4. stdin, stdout, stderr = client.exec_command('tail -n 1 -f server.log')
  5. while stdout.channel.recv_ready():
  6. solo_line = ""
  7. solo_line = stdout.channel.recv(1024)
  8. data_buffer += solo_line.decode('utf-8')
  9. print("This is the solo_line: " + solo_line.decode('utf-8'))
  10.  
  11. client.close()
  12.  
  13. return data_buffer
  14.  
  15. @bp.route('/exeAPI', methods=['GET', 'POST'])
  16. def exeAPI():
  17. if request.method == "POST":
  18.  
  19. # ssh set up
  20. client = paramiko.SSHClient()
  21. client.load_system_host_keys()
  22. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  23.  
  24. # Get host name from POST
  25. hostname = request.form['json_str'].replace('"', '')
  26. session['hostname'] = hostname
  27.  
  28. # Connect to hostname and execute create reports
  29. client.connect(hostname, username=USERNAME, password=PASSWORD)
  30.  
  31. print('started...')
  32.  
  33. #tail -f
  34. stdin, stdout, stderr = client.exec_command('tail -n 1 -f server.log')
  35. #execute remote API
  36. stdin_exe, stdout_exe, stderr_exe = client.exec_command('echo source "/home/user/exeAPI" | nc 127.0.0.1 40000')
  37.  
  38. data_buffer = ""
  39.  
  40. for line in iter(stdout.readline(), ""):
  41. data_buffer += line
  42. print(line, end="")
  43.  
  44. print('finished.')
  45.  
  46. client.close()
  47.  
  48. return data_buffer
Add Comment
Please, Sign In to add comment