如何从列表中重新附加和关闭多个屏幕会话

发布于 2024-08-05 22:07:52 字数 567 浏览 2 评论 0原文

我是 Ubuntu 9.04 用户。给定一个屏幕会话列表,如下所示:

9076.pts-30.moe (09/27/2009 11:30:08 PM)    (Attached)
8778.pts-24.moe (09/27/2009 11:29:46 PM)    (Detached)
8674.pts-0.moe  (09/27/2009 11:29:25 PM)    (Attached)
22649.pts-28.moe    (09/27/2009 11:51:46 AM)    (Detached)
22543.pts-24.moe    (09/27/2009 11:50:56 AM)    (Detached)
22228.pts-16.moe    (09/27/2009 11:49:59 AM)    (Detached)

我如何根据时间标准关闭多个屏幕?例如,所有屏幕在中午 12:00 之前启动。我通常会输入:

    screen -dr 22649.pts-28.moe
    exit
    ...

并手动关闭每一个,但这很乏味。提前致谢。

I am an Ubuntu 9.04 user. Given a list of screen sessions such as the following:

9076.pts-30.moe (09/27/2009 11:30:08 PM)    (Attached)
8778.pts-24.moe (09/27/2009 11:29:46 PM)    (Detached)
8674.pts-0.moe  (09/27/2009 11:29:25 PM)    (Attached)
22649.pts-28.moe    (09/27/2009 11:51:46 AM)    (Detached)
22543.pts-24.moe    (09/27/2009 11:50:56 AM)    (Detached)
22228.pts-16.moe    (09/27/2009 11:49:59 AM)    (Detached)

How would I close out multiple screens based on a time criterion? For instance, all screens initiated before 12:00 PM. I normally would type:

    screen -dr 22649.pts-28.moe
    exit
    ...

and close each one out manually, but this is tedious. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南烟雨〆相思醉 2024-08-12 22:07:53

下面是我杀死所有分离屏幕的方法:

screen -ls | grep Detached | awk -F" " '{print $1}' | xargs -I{} screen -X -S {} kill

如果你想强行杀死所有屏幕,只需将上面的 grep Detached 更改为 grep tached 即可。至少对我来说一直有效!

对于时间标准,您可以从以下内容开始:

screen -ls | grep Detached | awk -F " " '{print $2,$3,$4","$1}'

这将打印类似以下内容的内容:

(01/03/2012 02:10:42 AM),4504.test2
(01/03/2012 02:10:12 AM),4445.test1
(01/03/2012 02:02:58 AM),4333.test0

其中第一组是时间戳并用逗号分隔,是 PID.name。

因此您可以再次使用 /pipe 到 awk (或 awk -F"," '{print $1}' 来精确提取时间戳,在括号中)来解析括号内的时间..记住,screen -ls 总是最后列出最早的屏幕!

我还没有弄清楚如何自己进行时间标准过滤,如果可以的话,我将来会编辑它..祝你好运,伙计!

Here's how I kill all detached screens:

screen -ls | grep Detached | awk -F" " '{print $1}' | xargs -I{} screen -X -S {} kill

if you want to forcibly kill all screens, just change grep Detached above to grep tached. Works for me all the tine, at the very least!

for time criterion, you can start with this:

screen -ls | grep Detached | awk -F " " '{print $2,$3,$4","$1}'

this prints something like:

(01/03/2012 02:10:42 AM),4504.test2
(01/03/2012 02:10:12 AM),4445.test1
(01/03/2012 02:02:58 AM),4333.test0

where the first group is the timestamp and separated by a comma, is the PID.name.

so you could use/pipe to awk (or awk -F"," '{print $1}' to exactly extract the timestamps only, in parentheses) again to parse the time inside the parentheses.. remember, screen -ls always lists the earliest screen last!

I have not figured out how to do time criterion filtering myself, i'll edit this in the future if i could.. good luck buddy!

神回复 2024-08-12 22:07:53

您可以使用 -X 参数将命令发送到屏幕。因此,您可以通过说“screen -S 22649.pts-28.moe -X quit”从命令行关闭屏幕。

要按时间选择屏幕,我想您必须运行脚本来比较时间。

就我个人而言,我会在 python 中使用 os.popen() 和 time.strptime() 。

You can send commands to a screen using the -X parameter. So you can close a screen from the command line by saying "screen -S 22649.pts-28.moe -X quit".

To select the screens by time, I guess you have to run a script to compare the times.

Personally, I would use os.popen() and time.strptime() in python.

在风中等你 2024-08-12 22:07:53

点之前的数字(示例中的 22649)是屏幕进程的 PID。只需杀死它即可(kill 22649

The number before the dot (22649 in your example) is the PID of the screen process. Just kill it (kill 22649)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文