如何从命令行直接从启动多个分割的屏幕?

如何从命令行直接从启动多个分割的屏幕?

screen我在登录到服务器后使用ssh。到目前为止,我手动设置了屏幕窗口中的分割,并手动运行命令,如以下屏幕截图所示:

在此处输入图片描述

  • 顶部应该运行tail -n 1 -f /home/server/log/access.log
  • 右下部分应该运行htop
  • 左下角应该只是一个命令提示符

有没有办法通过命令/脚本来完成此操作,这样我就不必每次都手动重做?

答案1

对于窗口排列的具体情况,有一个屏幕命令可以将它们保存到文件中:layout dump。从man screen

layout dump [filename]

Write to a file the order of splits made in the current layout. This is
useful to recreate the order of  your  regions  used  in  your  current
layout.  Only  the  current  layout is recorded. While the order of the
regions are recorded, the sizes of  those  regions  and  which  windows
correspond  to  which regions are not. If no filename is specified, the
default is layout-dump, saved in the directory that the screen  process
was  started in. If the file already exists, layout dump will append to
that file. As an example:

           C-a : layout dump /home/user/.screenrc

will save or append the layout to the user's .screenrc file.

因此,一旦您手动进行安排,请按Ctrla:,然后输入layout dump /path/to/some/file。布局将保存到/path/to/some/file,然后您可以在新会话中使用以下命令恢复它:

screen -c /path/to/some/file

答案2

我想出了以下内容来创建我的问题中显示的输出,并遵循@muru 的精彩回答。使用layout dump给了我以下信息:

split
focus
split -v
focus

注意:波浪号 ( ~) 扩展不适用于,因此您需要使用layout dump而不是。~/layout.dmp/home/<username>/layout.dmp

然后我创建了以下内容.screenrc

# create the top screen
chdir /home/server/log
screen -t "Apache Log" tail -n 1 -f access.log
# split the screen and focus onto the new created space
split
focus
#create the bash
chdir /home/server/log
screen
# split vertically and focus onto the new area
split -v
focus
# create the htop screen
screen -t "Htop" htop
# focus twice to end up with the bash area active
focus
focus

现在我只需要输入screen并开始我想要的布局。我把这个留在这里作为给那些想知道的人的一个例子,但不要忘记给@muru 的答案点赞,因为他是让我能够解决这个问题的人。

相关内容