0

I am working on a flask project where I have created a User Interface whose purpose is to log into a Linux server using ssh and run a bash script present on the server that logs some data into a file and I want that data from the file to be populated onto the webpage as live logs. So that the logs can be seen from the UI itself and there is no need to manually log into the server. I am using the subprocess module of python to run another script whose purpose is to ssh into the server and run the other script that is present on the server.

subprocess.check_output(['bash','script.sh', username, server_ip, password])

the script.sh looks like

#!/bin/bash
sshpass -p $3 ssh -o StrictHostKeyChecking=no -l $1 $2 "sudo su -c 'start_maintenance; cd /var/log; tailf maintenance.log'"

where start_maintenance is an alias that runs the maintenance script and maintenance.log is the file present in /var/log that will store the logs that are generated during the maintenance activity.

The issue here is that this method is not showing live logs on the screen. I can only successfully populate data from a static file that does not have data still being written into it. I am looking for a way with which I can print my data onto the webpage as soon as it is being written in the maintenance.log file.

Can WebSocket or AJAX be used to achieve this? I am not able to find any relevant information online.

0 Answers0