eohippus eohippus - 2 months ago 7
Python Question

Return prompt after accessing nohup.out (bash)

I'm running a Python script from bash using

nohup
. The script is executed via my bashrc as part of a shell function. If I run it like this:

function timer {
nohup python path/timer.py $1 $2 > path/nohup.out 2>&1 &
echo 'blah'
}


Everything works and I get my prompt back. However, if instead of
echo
I call
tail
to access the end of the nohup output file, like this:

function timer {
nohup python path/timer.py $1 $2 > path/nohup.out 2>&1 &
tail -f path/nohup.out
}


my prompt is not returned. I would like to see the contents of nohup.out and get back to the prompt without having to use CTRL-c.

I have followed the advice here, but adding
</dev/null
yields the same results as above.

sat sat
Answer

You won't get prompt.

Because, tail -f will always watch the file (path/nohup.out) to output appended data as the file grows. You can try tail -n to get last 10 lines of path/nohup.out.

Comments