7

I've written a simple bash script that ssh's into 3 hosts (2 remote, 1 my own for testing) and runs a long running gui program that outputs text to the terminal that I'd like to log.

#!/bin/bash ssh -f -X user@remote1 '(python -u long_running_program.py &> ~/log1.txt)' ssh -f -X user@remote2 '(python -u long_running_program.py &> ~/log2.txt)' ssh -f -X user@localhost '(python -u long_running_program.py &> ~/log3.txt)' multitail -s 3 ~/log* 

From the above, ssh is called with the f parameter to run in the background and allow the script to continue execution. On the remote server, the python program is called with the unbuffered switch and the output redirected to a log file (note that the home directories of the remote and local machines are all on a network mounted drive so using ~ gives the same path on all of them).

The above technically works, however the 2 logs (log1,log2) from the remote machine are very slow to update. It can be 20+seconds before the file is updated (regardless of if you are using multitail, vi, etc to view the file), while the local log file (log3) update is immediate.

To confirm this should not be happening, I can manually ssh into the remotes and run the program without redirecting the output to file. The output is streamed continuously without delay, as expected. I have also tried various things like trying to turn off buffering and using script/tee/etc to no avail.

Does anyone know what's causing this and/or how to resolve it?

4
  • Which GUI program are you using? Is it a network application? Have you tried using other (possibly non-GUI) programs to reproduce the problem?
    – igal
    CommentedNov 5, 2017 at 18:35
  • 1
    Seems that changes on the network mounted drive by the remote hosts do not instantly become visible to localhost. Perhaps you could pipe through ssh like this ssh -f -X user@remote1 '(python -u long_running_program.py &>1)' >~/log1.txt
    – David
    CommentedNov 8, 2017 at 12:52
  • Do you have to run the python scripts from the local machine or is it an option to execute them remote only? In the second case I would give rsyslogd a chance. Run python scripts on machines separately with local logging via rsyslogd, configure rsyslogd to send logging data to central host immediately.CommentedMar 10, 2020 at 11:33
  • Correction to @David’s excellent answer: change &>1 to 2>&1.
    – Amir
    CommentedDec 3, 2020 at 7:29

1 Answer 1

1

I suggest using pssh which was specifically designed for executing multiple parallel SSH sessions, instead of running several serial SSH commands concurrently.

E.g.,

pssh -i -H user@remote1 -H user@remote2 -H user@localhost '(python -u long_running_program.py &> ~/log$PSSH_NODENUM.txt)' 
2
  • That’s a good piece of advice, but it doesn’t answer the question.
    – Amir
    CommentedDec 3, 2020 at 7:20
  • Ah yeah, well it does but not explicitly: ~/log$PSSH_NODENUM.txt
    – TobiV
    CommentedDec 4, 2020 at 8:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.