如何用命令启动 Unix screen 命令?

发布于 2024-07-14 00:13:53 字数 617 浏览 3 评论 0原文

根据Unix“screen”命令的文档,您可以配置它在 .screenrc 中以一堆默认屏幕开始,每个屏幕运行您指定的命令。

这是我的配置:

# Default screens
screen -t "shell_0"  1
screen -t "autotest" 2 cd ~/project/contactdb ; autotest

它不会运行自动测试命令。 当我启动 screen 时,我尝试运行 autotest 的窗口会立即关闭。

我也尝试过......

screen -t "autotest" 2 cd ~/project/contactdb

同样的结果。

我也尝试过...

screen -t "autotest" 2 ls

那里也有同样的结果。

让它在启动时在给定屏幕中运行命令的秘诀是什么?

According to the docs for the Unix "screen" command, you can configure it in .screenrc to start with a bunch of default screens, each running a command that you specify.

Here's my cofig:

# Default screens
screen -t "shell_0"  1
screen -t "autotest" 2 cd ~/project/contactdb ; autotest

It will not run the autotest command. That window where I'm trying to run autotest just closes instantly when I start screen.

I also tried it with just...

screen -t "autotest" 2 cd ~/project/contactdb

Same result.

I also tried...

screen -t "autotest" 2 ls

Same result there too.

What's the secret to getting it to run a command in a given screen on startup?

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

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

发布评论

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

评论(6

盛装女皇 2024-07-21 00:13:53

你的程序正在运行(好吧,除了 cd),只是它是在没有父 shell 的情况下运行的,所以一旦它完成,它就会退出,你就完成了。

你可以这样做:

screen -t "autotest" 2 bash -c 'cd ~/project/contactdb ; autotest'

产生两个壳,但生活可能会继续下去。

Your program is being run (well, except the cd), it's just that it's being run without a parent shell, so as soon as it completes, it exits and you're done.

You could do:

screen -t "autotest" 2 bash -c 'cd ~/project/contactdb ; autotest'

Spawns two shells, but life will probably go on.

陈年往事 2024-07-21 00:13:53

试试这个:

$ screen -S 'tailf messages' -d -m tailf /var/log/messages

然后你可以这样做:

$ screen -ls
1234.tailf messages

然后是:

$screen -r 1234

Try this:

$ screen -S 'tailf messages' -d -m tailf /var/log/messages

Then later you can do:

$ screen -ls
1234.tailf messages

Followed by:

$screen -r 1234
蓝海 2024-07-21 00:13:53

这可能会有所帮助,但可能并不完全是您想要的。

将“zombie az”或“defzombie az”作为 .screenrc 的第一行。 “az”可以是您想要的任意 2 个键。 现在,当屏幕应该关闭时(例如,命令执行完毕),它实际上不会关闭; 点击“a”将关闭它,点击“z”将重新执行附加到该屏幕的命令。

我在屏幕用户手册中找到了这一点。

This might help but may not be entirely what you want.

Put "zombie az" or "defzombie az" as the first line of your .screenrc. "az" can be whatever 2 keys you'd like. Now, when a screen ought to close (command finished executing, for instance), it won't actually close; hitting 'a' will close it, hitting 'z' will re-execute the command attached to that screen.

I found that at the screen user's manual.

空城之時有危險 2024-07-21 00:13:53

您还可以将字符“填充”到屏幕中,就像您键入它们一样。

以下是您如何使用示例来做到这一点:


screen -t "shell_0"  1

# create the following screen in the desired dir, instead of cd-ing afterwards :)
chdir ~/project/contactdb
screen -t "autotest" 2

# (without this sometimes screens fail to start correctly for me)
sleep 5

# paste some text into screen number 2:
select 2
stuff "autotest\012"

You can also "stuff" characters into the screen as if you had typed them.

Here's how you can do that with your example:


screen -t "shell_0"  1

# create the following screen in the desired dir, instead of cd-ing afterwards :)
chdir ~/project/contactdb
screen -t "autotest" 2

# (without this sometimes screens fail to start correctly for me)
sleep 5

# paste some text into screen number 2:
select 2
stuff "autotest\012"
不顾 2024-07-21 00:13:53

这是我的样子。 看起来效果很好。 我认为括号可能会导致问题,或者如果命令“自动测试”不存在,屏幕将不会打开窗口。

<前><代码>屏幕-t zsh 1
屏幕 -t emacs 2 emacs -nw
屏幕-t mutt 3 mutt
监控开启
屏幕-t mc 4 mc -s
screen -t elinks 4 elinks

Here's how mine looks. It seems to work fine. I think either the parenthesis might be causing the problem or screen will not open a window if the command "autotest" does not exist.

screen -t zsh 1
screen -t emacs 2 emacs -nw
screen -t mutt 3 mutt
monitor on
screen -t mc 4 mc -s
screen -t elinks 4 elinks
不疑不惑不回忆 2024-07-21 00:13:53

我就是这样做的。

screen -t shell_0
chdir ~/project/contactdb
screen -t autotest autotest

上述内容似乎是通过屏幕按程序进行评估的。 首先,我们建立一个标题为 shell_0 的新屏幕。 由于我们没有提供其他选项,因此当前工作目录将是父 shell 或用户主目录的目录。 然后,我们将新屏幕的默认目录设置为~/project/contactdb。 接下来,我们建立一个运行 autotest 命令的新屏幕。

窗口号(n)是可选的,我通常省略它。

Here's how I'd do it.

screen -t shell_0
chdir ~/project/contactdb
screen -t autotest autotest

The above appears to be evaluated procedurally by screen. First we establish a new screen with the title shell_0. Since we gave no other options, current working directory will be that of the parent shell or the user's home directory. We then set the default directory for new screens to ~/project/contactdb. Next, we establish a new screen running the autotest command.

Window number (n) is optional, I generally omit it.

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