linux - running a process and tailing a file simultaneously

76 views Asked by At

I want a run a long task on a remote machine (with python fabric using ssh). It logs to a file on the remote machine. What I want to do is to run that script and tail (actively display) the log file content until the script execution ends. The problem with

python test.py & tail -f /tmp/out

is that it does not terminate when test.py exits. Is there a simple linux trick I can use to do this or do I have to make a sophisticated script to continuously check the termination of the first process?

1

There are 1 answers

0
hek2mgl On BEST ANSWER

I would simply start the tail in background and the python process in foreground. When the python process finishes you can kill the tail, like this:

#!/bin/bash

touch /tmp/out # Make sure that the file exists
tail -f /tmp/out &
pid=$!
python test.py
kill "$pid"