nohup 命令通常会把输出重定向到当前目录下的 nohup.out 文件(除非你手动指定了其他文件)。远程查看日志本质上就是远程登录服务器 + 查看日志文件。
下面按常见场景给你总结几种方式。
ssh user@server_ip
# 查看当前目录
ls -l nohup.out
# 实时查看日志
tail -f nohup.out
# 查看最后 100 行
tail -n 100 nohup.out
# 从头查看
cat nohup.out
# 分页查看
less nohup.out
比如你启动时是:
nohup python app.py > app.log 2>&1 &
那远程查看就是:
tail -f app.log
ssh user@server_ip "tail -n 200 /path/to/nohup.out"
ssh user@server_ip "tail -f /path/to/nohup.out"
按 Ctrl + C 退出。
find / -name nohup.out 2>/dev/null
ps -ef | grep your_program
ls -l /proc/进程ID/fd
screen / tmuxtmux new -s myapp
python app.py
# Ctrl+B D 退出
远程随时:
tmux attach -t myapp
import logging
logging.basicConfig(filename='app.log')
-u):nohup python -u app.py > app.log 2>&1 &
du -h nohup.out
如果你愿意,可以告诉我:
我可以给你更精确的命令。