Suppose I have a python script script.py
from time import sleep
for i in range(3):
print(i)
sleep(1)
print('done')
which I want to run on a remote server via an ssh command e.g.
ssh me@server "python script.py"
If I do the above verbatim, I get the whole output 0 1 2 done
three seconds after I started the script. Instead, I would like to see the output immediately as it is generated by the script, i.e. 0
-one second later- 1
-one second later- 2
-one second later- done
.
I've seen similar questions regarding viewing the log file, but is there an easy way to do this (e.g. without intermediate logging to a file on the server)?
python -u
. – Kamil Maciorowski Jun 25 '21 at 05:11