温馨提示×

怎样远程查nohup日志

小樊
55
2026-10-12 07:51:20
栏目: 编程语言

“远程查 nohup 日志”通常分两步:先远程连到服务器,再查看 nohup 输出的日志文件。下面按常见场景说明。


一、远程登录服务器

1. SSH 登录(最常用)

ssh user@远程服务器IP

例如:

ssh root@192.168.1.100

如果有端口:

ssh -p 22 user@host

二、找到 nohup 日志位置

1. 默认 nohup 日志

如果你是这样启动的:

nohup python app.py &

日志默认在:

nohup.out

查看:

ls -l nohup.out

2. 指定了日志文件(更推荐)

nohup python app.py > app.log 2>&1 &

日志就在:

app.log

三、查看 nohup 日志内容

1. 实时查看(最常用)

tail -f nohup.out

或

tail -f app.log

退出:Ctrl + C


2. 查看最后 N 行

tail -n 100 nohup.out

3. 从头查看

cat nohup.out

或分页:

less nohup.out

q 退出


4. 查找关键字

grep "ERROR" nohup.out

四、不登录服务器直接远程看(进阶)

1. SSH 直接执行命令

ssh user@host "tail -f /path/to/nohup.out"

2. 远程实时日志(推荐)

ssh user@host "tail -f /home/user/app/app.log"

五、常见问题

❌ nohup.out 找不到?

find / -name nohup.out 2>/dev/null

❌ 日志不更新?

  • 程序可能没写缓冲
  • 可加:
python -u app.py > app.log 2>&1 &

如果你愿意,可以告诉我:

  • 用的是 Linux / macOS / Windows
  • 程序是 Python / Java / Node
  • 是否 Docker / 云服务器

我可以给你更精确的命令。

0 踩