nohup 本身不会直接报错,它只是让程序在后台运行、忽略挂断信号,并把输出默认写到 nohup.out 或你重定向的文件里。
所谓“nohup日志报错”,通常是 程序运行出错,被写进了日志文件。下面按常见场景说明怎么查。
nohup command &
日志在:
nohup.out
(在当前工作目录)
nohup command > app.log 2>&1 &
日志在:
app.log
tail -f app.log
# 或
tail -f nohup.out
tail -n 100 app.log
grep -i error app.log
grep -i exception app.log
grep -i "failed" app.log
例如:
Exception in thread "main"Traceback (most recent call last)command not found✅ 解决:看具体报错行,不是 nohup 的问题
Permission denied
✅ 检查:
ls -l app.log
whoami
Address already in use
✅ 查端口:
netstat -tunlp | grep 端口号
nohup 启动的环境可能没有 PATH / JAVA_HOME
nohup: failed to run command ‘java’: No such file or directory
✅ 解决:
nohup /usr/local/jdk/bin/java -jar app.jar > app.log 2>&1 &
或在脚本里 source ~/.bashrc
df -h
日志写不进去也会“看起来没反应”
ps -ef | grep 程序名
或
jobs -l
nohup ./start.sh > app.log 2>&1 &
start.sh 里:
#!/bin/bash
source ~/.bashrc
cd /path/to/app
java -jar app.jar
你可以贴出:
我可以直接告诉你是哪一步出的问题 + 怎么改。