要在 CentOS 上实现使用 nohup 命令运行的程序的日志远程查看,你可以使用以下方法之一:
方法一:使用 screen
或 tmux
工具
安装 screen
或 tmux
工具。如果没有安装,可以使用以下命令安装:
sudo yum install screen
或
sudo yum install tmux
启动 screen
或 tmux
会话:
screen -S your-session-name
或
tmux new-session -s your-session-name
在会话中运行你的程序,并使用 nohup 命令将输出重定向到日志文件:
nohup your-command > your-log-file.log 2>&1 &
按 Ctrl
+ A
然后按 D
键(对于 screen
)或按 Ctrl
+ B
然后按 D
键(对于 tmux
)来分离会话。此时,你的程序将在后台运行。
使用 SSH 连接到远程服务器,并重新连接到之前的会话:
对于 screen
:
screen -r your-session-name
对于 tmux
:
tmux attach-session -t your-session-name
查看日志文件:
cat your-log-file.log
方法二:使用 ssh
和 tail
命令实时查看日志
在远程服务器上运行程序,并使用 nohup 命令将输出重定向到日志文件:
nohup your-command > your-log-file.log 2>&1 &
使用 SSH 连接到远程服务器:
ssh user@remote-server-ip
使用 tail
命令实时查看日志文件:
tail -f your-log-file.log
这样,你可以实时查看远程服务器上使用 nohup 命令运行的程序的日志。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:centos nohup日志怎么导出