前言

最近答疑群友如何后台运行 ssh 连接后的操作,整理了下日常常见的后台执行方式,方便知识梳理。

1、nohup方式

1
2
# nohup sh shell.sh &
查看日志:tail -f nohup.out

2、disown方式

1
2
# sh shell.sh & disown
查看日志:断开终端后,不能再查看日志

3、screen方式

执行screen,如果命令不存在,需要先安装:

1
# yum install screen -y

新建一个屏幕:

1
# screen -S screen_name

执行命令:

1
# sh shell.sh

依次按 Ctrl+A 与 D (无 Ctrl) 脱离该屏幕,此时程序仍运行在后台。

……

阅读全文