Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (initial ssh setup)
- ...
- data_buffer = ""
- stdin, stdout, stderr = client.exec_command('tail -n 1 -f server.log')
- while stdout.channel.recv_ready():
- solo_line = ""
- solo_line = stdout.channel.recv(1024)
- data_buffer += solo_line.decode('utf-8')
- print("This is the solo_line: " + solo_line.decode('utf-8'))
- client.close()
- return data_buffer
- @bp.route('/exeAPI', methods=['GET', 'POST'])
- def exeAPI():
- if request.method == "POST":
- # ssh set up
- client = paramiko.SSHClient()
- client.load_system_host_keys()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- # Get host name from POST
- hostname = request.form['json_str'].replace('"', '')
- session['hostname'] = hostname
- # Connect to hostname and execute create reports
- client.connect(hostname, username=USERNAME, password=PASSWORD)
- print('started...')
- #tail -f
- stdin, stdout, stderr = client.exec_command('tail -n 1 -f server.log')
- #execute remote API
- stdin_exe, stdout_exe, stderr_exe = client.exec_command('echo source "/home/user/exeAPI" | nc 127.0.0.1 40000')
- data_buffer = ""
- for line in iter(stdout.readline(), ""):
- data_buffer += line
- print(line, end="")
- print('finished.')
- client.close()
- return data_buffer
Add Comment
Please, Sign In to add comment