Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash linux-同时运行进程和跟踪文件_Bash_Shell_Tail - Fatal编程技术网

Bash linux-同时运行进程和跟踪文件

Bash linux-同时运行进程和跟踪文件,bash,shell,tail,Bash,Shell,Tail,我希望在远程机器上运行一个长任务(使用ssh的python结构)。 它记录到远程计算机上的一个文件。 我要做的是运行该脚本并跟踪(主动显示)日志文件内容,直到脚本执行结束。 问题在于 python test.py & tail -f /tmp/out 它不会在test.py退出时终止。 有没有一个简单的linux技巧可以用来实现这一点,或者我必须制作一个复杂的脚本来持续检查第一个进程的终止情况?我只需在后台启动尾部,在前台启动python进程。当python进程完成时,您可以杀死尾部,

我希望在远程机器上运行一个长任务(使用ssh的python结构)。 它记录到远程计算机上的一个文件。 我要做的是运行该脚本并跟踪(主动显示)日志文件内容,直到脚本执行结束。 问题在于

python test.py & tail -f /tmp/out
它不会在test.py退出时终止。
有没有一个简单的linux技巧可以用来实现这一点,或者我必须制作一个复杂的脚本来持续检查第一个进程的终止情况?

我只需在后台启动
尾部,在前台启动python进程。当python进程完成时,您可以杀死
尾部
,如下所示:

#!/bin/bash

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