我有以下脚本:
tail -f nohup.out
echo 5
当我按Ctrl+ Contail -f
时,脚本停止运行:5
未打印。echo 5
停止命令后如何运行tail
命令?
Ctrl+C sends the SIGINT signal to all the processes in the foreground process group. While tail
is running, the process group consists of the tail
process and the shell running the script.
Use the trap
builtin to override the default behavior of the signal.
trap " " INT
tail -f nohup.out
trap - INT
echo 5
The code of the trap does nothing, so that the shell progresses to the next command (echo 5
) if it receives a SIGINT. Note that there is a space between the quotes in the first line; any shell code that does nothing will do, except an empty string which would mean to ignore the signal altogether (this cannot be used because it would cause tail
to ignore the signal as well). The second call to trap
restores the default behavior, so that after the third line a Ctrl+C will interrupt the script again.
#!/bin/bash
trap "echo 5" SIGINT SIGTERM
tail -f nohup.out
您可以tail
在新的 shell 中启动,如下所示:
#!/bin/bash
bash -i -c 'tail -f nohup.out'
echo 5
如rwos 所述,但添加了内联陷阱。
bash -i -c "trap ' ' SIGINT; tail -F '$1'; trap - SIGINT"
在发出后续 SIGINT 信号时,这将在不关闭腻子会话的情况下工作(这是我的问题)
在 bash 中以单个 & 符号结束该行,以异步方式在后台运行命令
tail -f nohup.out &
在 perl 中查找 File:Tail,在不同的项目中多次使用它来自动跟踪日志并执行日志输出的特定操作。
google ftp-upload-mon 我上传到 sourceforge 的一个项目,它使用 File:Tail to tail -f xferlogs