linux之screen运行脚本

Posted ~小疯子~

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux之screen运行脚本相关的知识,希望对你有一定的参考价值。

1.新开一个screen :

[root@localhost ~]# screen

2.进入screen执行脚本:

[root@localhost ~]# 省略...

3.脚本执行过程中可以关闭你的终端连接:

[root@localhost ~]# exit

4.查看脚本是否还在运行(或窗口状态):

[root@localhost ~]# screen -ls
There is a screen on:
       23790.pts-1.localhost  (Attached)  //这说明本地窗口连接没有关闭
1 Socket in /var/run/screen/S-xinfang.

[root@localhost ~]#

[root@localhost ~]# screen -ls
There is a screen on:
       23790.pts-1.localhost  (Detached)  //这说明本地窗口连接已经关闭,但screen并未关闭
1 Socket in /var/run/screen/S-xinfang.

[root@localhost ~]#

5.查看主机cpu负载指数:

[root@localhost ~]# top

load average: 0.43

6.客户端切回screen窗口界面查看脚本执行状况:

[root@localhost ~]# screen -x 23790

7.推出screen:

[root@localhost ~]# exit

[screen isterminating]    //标识该screen已经关闭

8.查看screen窗口是否关闭:

[root@localhost ~]# screen -ls
No Sockets found in/var/run/screen/S-xinfang.   // 标识已经没有sockets 窗口连接,screen已经成功退出

[root@localhost ~]#

9.附带screen的相关命令:

[root@localhost ~]# screen -help
Use: screen [-opts] [cmd [args]]
 or: screen -r [host.tty]

Options:
-a           Force all capabilities into each window's termcap.
-A-[r|R]    Adapt all windows to the new display width &height.
-cfile      Read configuration file instead of '.screenrc'.
-d(-r)      Detach the elsewhere running screen (and reattach here).
-dmSname    Start as daemon: Screen session in detached mode.
-D(-r)      Detach and logout remote (and reattach here).
-D-RR       Do whatever is needed to get a screen session.
-exy        Change command characters.
-f           Flow control on, -fn = off, -fa = auto.
-hlines     Set the size of the scrollback history buffer.
-i           Interrupt output sooner when flow control is on.
-l           Login mode on (update /var/run/utmp), -ln = off.
-list        or -ls. Do nothing, just list our SockDir.
-L           Turn on output logging.
-m           ignore $STY variable, do create a new screen session.
-O           Choose optimal output rather than exact vt100 emulation.
-pwindow    Preselect the named window if it exists.
-q           Quiet startup. Exits with non-zero return code ifunsuccessful.
-r           Reattach to a detached screen process.
-R           Reattach if possible, otherwise start a new session.
-sshell     Shell to execute rather than $SHELL.
-S sockname   Name this session.sockname instead of ...
-ttitle     Set title. (window's name).
-Tterm      Use term as $TERM for windows, rather than "screen".
-U           Tell screen to use UTF-8 encoding.
-v           Print "Screen version 4.00.03 (FAU) 23-Oct-06".
-wipe        Do nothing, just clean up SockDir.
-x           Attach to a not detached screen. (Multi display mode).
-X           Execute as a screen command in the specified session.
[root@localhost ~]#

以上是关于linux之screen运行脚本的主要内容,如果未能解决你的问题,请参考以下文章

Linux系统管理初步系统日志与screen程序

Linux让程序后台运行命令之screen与nohup

linux 之 screen

Linux8.8 screen工具

linux运维之分析系统负载及运行状况

sh 脚本快速扫描S.M.A.R.T. Linux中所有硬盘设备的运行状况(至少从/ dev / sda到/ dev / sdz的所有硬盘设备)