GNU 屏幕:从 bash 脚本启动时 -S 选项不起作用

发布于 2024-12-08 21:47:11 字数 663 浏览 1 评论 0原文

拥有如此简单的 bash 脚本:

/bin/bash
screen -dm -S "backup"
wget -O backup-$(date +%Y-%m-%d).txt http://link-to-very-huge-file/

问题是:当执行 screen -dm -S "backup" 时,会出现新的 screen 会话。但它没有命名!当我(从 ssh)执行 screen -ls 时,它给了我:

(10/09/2011 04:35:05 PM)(已分离)
1969.VNC (10/09/2011 01:53:45 PM)(分离)
910.minecraft (10/09/2011 12:59:29 PM)(分离)

最后两个是我自己创建的。但是第一个是由 bash 脚本创建的,没有名称,甚至没有 id!

当我自己执行 screen -dm -S "backup" 时,它工作正常并为我提供了命名的屏幕会话:

3527.backup (10/09/2011 04:44:40 PM)(已分离)

但为什么脚本效果不好呢?怎样才能让它正常工作呢?

Having such simple bash script:

/bin/bash
screen -dm -S "backup"
wget -O backup-$(date +%Y-%m-%d).txt http://link-to-very-huge-file/

The problem is: when screen -dm -S "backup" executes, new screen session appears. But it's not named! When I (from ssh) do screen -ls it gives me:

(10/09/2011 04:35:05 PM)        (Detached)
1969.VNC        (10/09/2011 01:53:45 PM)        (Detached)
910.minecraft   (10/09/2011 12:59:29 PM)        (Detached)

I've created the last two myself. But the first one, created by bash script, doesn't have name and even doesn't have id!

When I do screen -dm -S "backup" myself, it works fine and gives me the named screen session:

3527.backup (10/09/2011 04:44:40 PM)        (Detached)

But why script does bad? How to make it work propertly?

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

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

发布评论

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

评论(1

一直在等你来 2024-12-15 21:47:11

这很奇怪;它对我有用。

您可以复制并粘贴 bash 脚本的准确内容吗?您问题中的第一行缺少 #!,并且在 screen 命令后面的一行上有 wget 命令。这让我怀疑问题出在您没有向我们展示的某些代码中。

这是我刚刚尝试过的。 (我添加了 -c /dev/null 以避免加载相当复杂的 .screenrc 文件):

$ screen -ls
There is a screen on:
        2454.pts-1.kvetch       (09/09/2011 11:00:03 AM)        (Detached)
1 Socket in /var/run/screen/S-kst.

$ cat foo.bash
#!/bin/bash

screen -dm -S FROM_BASH -c /dev/null sleep 12345
$ ./foo.bash
$ screen -ls
There are screens on:
        10384.FROM_BASH (10/09/2011 01:22:48 PM)        (Detached)
        2454.pts-1.kvetch       (09/09/2011 11:00:03 AM)        (Detached)
2 Sockets in /var/run/screen/S-kst.

$ 

我在 Ubuntu 11.04 上使用 screen 4.00.03jw4。

That's odd; it works for me.

Can you copy-and-paste the exact contents of the bash script? The one in your question is missing the #! on the first line, and has the wget command on a line following the screen command. This makes me suspect the problem is in some code you haven't shown us.

Here's what I just tried. (I added the -c /dev/null to avoid loading my fairly elaborate .screenrc file):

$ screen -ls
There is a screen on:
        2454.pts-1.kvetch       (09/09/2011 11:00:03 AM)        (Detached)
1 Socket in /var/run/screen/S-kst.

$ cat foo.bash
#!/bin/bash

screen -dm -S FROM_BASH -c /dev/null sleep 12345
$ ./foo.bash
$ screen -ls
There are screens on:
        10384.FROM_BASH (10/09/2011 01:22:48 PM)        (Detached)
        2454.pts-1.kvetch       (09/09/2011 11:00:03 AM)        (Detached)
2 Sockets in /var/run/screen/S-kst.

$ 

I'm using screen 4.00.03jw4 on Ubuntu 11.04.

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