通过 bash 脚本关闭屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5402040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 23:39:35  来源:igfitidea点击:

Closing screen by bash script

linuxbashshellgnu-screen

提问by Sebi

I am trying to close a screen(1)by script where application is running. How could I do it? I am doing screen -dmS name stuff_to_executebut it creates a new one. I tried searching how to do this but found nothing.

我正在尝试关闭screen(1)运行应用程序的脚本。我怎么能做到?我正在做,screen -dmS name stuff_to_execute但它创建了一个新的。我尝试搜索如何执行此操作,但一无所获。

回答by sarnold

From the screen(1)manpage:

screen(1)联机帮助页:

-d -mStart screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.

-d -m以“分离”模式启动屏幕。这会创建一个新会话,但不会附加到它。这对于系统启动脚本很有用。

So I don't think -dmSwill ever close a running screen(1).

所以我认为-dmS永远不会关闭跑步screen(1)

Do you want to killthe specified screen(1)instance? Or do you simply wish to force it to be detached?

你想杀死指定的screen(1)实例吗?或者你只是想强迫它分离?

If you want to kill: screen -S name -X quit

如果你想杀人: screen -S name -X quit

If you want to detach: screen -dS name

如果你想分离: screen -dS name

回答by reencode

This is what I use to close all screens:

这是我用来关闭所有屏幕的:

screen -ls | grep Detached | awk '{print }' | cut -f1 -d'.' | while read in; do screen -X -S $in quit; done 

It greps for the screen id and quits them all by id.

它搜索屏幕 id 并按 id 将它们全部退出。

回答by Raja Sami

:~$ screen -list

There are screens on:
23308.rsamikan-3 (Monday 20 July 2015 04:42:05 IST) (Detached)
23014.rsamikan-2 (Monday 20 July 2015 04:41:53 IST) (Detached)
22730.rsamikan-1 (Monday 20 July 2015 04:41:44 IST) (Detached)
16037.rsamikan-remote (Monday 20 July 2015 02:51:37 IST) (Attached) 4 Sockets in /var/run/screen/S-rsamikan.

屏幕上有:
23308.rsamikan-3(2015 年 7 月 20 日星期一 04:42:05 IST)(独立)
23014.rsamikan-2(2015 年 7 月 20 日星期一 04:41:53 IST)(独立)
22730.rsamikan (2015 年 7 月 20 日星期一 04:41:44 IST)(独立)
16037.rsamikan-remote(2015 年 7 月 20 日星期一 02:51:37 IST)(附加)/var/run/screen/S-rsamikan 中的 4 个套接字。

I have kill and wipe the detached screen only with the following script.

我仅使用以下脚本杀死并擦除了分离的屏幕。

:~$ **screen -list | grep Detached | awk '{print }' | while read in; do screen -X -S $in quit; done**

:~$ screen -list

There is a screen on:

有一个屏幕:

16037.rsamikan-remote (Monday 20 July 2015 02:51:37 IST) (Attached) 1 Socket in /var/run/screen/S-rsamikan.

16037.rsamikan-remote(2015 年 7 月 20 日星期一 02:51:37 IST)(附件)/var/run/screen/S-rsamikan 中的 1 个套接字。

回答by troyfolger

Sometimes a stubborn script holding open a screen can be killed by sending it an abort key sequence:

有时,可以通过向它发送一个中止键序列来杀死一个打开屏幕的顽固脚本:

screen -X -S "script0$scriptID" stuff "^C"