在 Debian(或其他 Linux)下用 nohup 启动的程序,日志通常写在:
nohup.out(默认)nohup xxx > app.log 2>&1 &下面按常见场景讲怎么“监控”这些日志。
tail -f nohup.out
或指定日志文件:
tail -f /path/to/app.log
退出:Ctrl + C
tail -n 100 -f nohup.out
tail -F nohup.out
-F=-f+ 文件不存在会等待
tail -f nohup.out | grep ERROR
tail -f nohup.out | grep --color=auto ERROR
multitail nohup.out app.log
安装:
sudo apt install multitail
watch -n 5 "tail -n 20 nohup.out"
tail -f nohup.out | grep ERROR | while read line; do
echo "$line" | mail -s "App Error" you@example.com
done
ps aux | grep 程序名
或
jobs -l
启动时就控制日志:
nohup python app.py > app.log 2>&1 &
并配合 logrotate 管理日志。
如果你愿意,可以告诉我:
我可以给你更具体的方案。