Screen -X exec 命令不起作用,直到手动连接

Screen -X exec 命令不起作用,直到手动连接

我有一个批处理脚本,用于在屏幕内启动 Java 服务器应用程序。命令如下:

cd /dir/ && screen -A -m -d -S javascreen java -Xms640M -Xmx1024M -jar javaserverapp.jar nogui

运行批处理脚本后,它会启动服务器并将其放入正确的屏幕中。如果我之后列出我的屏幕,我会看到类似以下内容:

user@gtwy /dir $ screen -list
There is a screen on:
        16180.javascreen       (Detached)
1 Socket in /var/run/screen/S-user.

但是,我还有第二个批处理脚本,它会向此服务器发送自动命令,并以不同的 crontab 间隔运行。由于应用程序的工作方式,我向它发送了如下命令(此命令告诉它提醒已连接的用户“测试 123”):

screen -X exec .\!\! echo say testing 123

我也尝试过:

screen -R -X exec .\!\! echo say testing 123
screen -S javascreen -X exec .\!\! echo say testing 123

不幸的是,这些命令不起作用。它们甚至没有给我一个错误消息,它们什么也没做。

但是 - 如果我先手动连接到屏幕(使用以下命令),然后断开连接,现在我可以完美地运行上述任何命令。如果我在这里说得不够清楚,我可以用视频演示这一点。

screen -r -d

提前致谢。

更新:以下是 /etc/screenrc 的重要部分。它应该是完全原始的,我从未编辑过此文件。

# VARIABLES
# ===============================================================
# No annoying audible bell, using "visual bell"
# vbell on                              # default: off
# vbell_msg "   -- Bell,Bell!! --   "   # default: "Wuff,Wuff!!"

# Automatically detach on hangup.
  autodetach on                         # default: on

# Don't display the copyright page
  startup_message off                   # default: on

# Uses nethack-style messages
# nethack on                            # default: off

# Affects the copying of text regions
  crlf off                              # default: off

# Enable/disable multiuser mode. Standard screen operation is singleuser.
# In multiuser mode the commands acladd, aclchg, aclgrp and acldel can be used
# to enable (and disable) other user accessing this screen session.
# Requires suid-root.
  multiuser off

# Change default scrollback value for new windows
  defscrollback 1000                    # default: 100

# Define the time that all windows monitored for silence should
# wait before displaying a message. Default 30 seconds.
  silencewait 15                        # default: 30

# bufferfile:   The file to use for commands
#               "readbuf" ('<') and  "writebuf" ('>'):
  bufferfile            $HOME/.screen_exchange
#
# hardcopydir:  The directory which contains all hardcopies.
# hardcopydir           ~/.hardcopy
# hardcopydir           ~/.screen
#
# shell:  Default process started in screen's windows.
# Makes it possible to use a different shell inside screen
# than is set as the default login shell.
# If begins with a '-' character, the shell will be started as a login shell.
# shell                 zsh
# shell                 bash
# shell                 ksh
  shell -$SHELL

# shellaka '> |tcsh'
# shelltitle '$ |bash'

# emulate .logout message
  pow_detach_msg "Screen session of \$LOGNAME \$:cr:\$:nl:ended."

# caption always " %w --- %c:%s"
# caption always "%3n %t%? @%u%?%? [%h]%?%=%c"

# advertise hardstatus support to $TERMCAP
# termcapinfo  * '' 'hs:ts=\E_:fs=\E\\:ds=\E_\E\\'

# set every new windows hardstatus line to somenthing descriptive
# defhstatus "screen: ^En (^Et)"

# don't kill window after the process died
# zombie "^["

答案1

Sadrul 在 #screen (Freenode) 上给出了这个答案,并且有效:

使用 -X 命令,尝试指定窗口编号(例如 screen -p0 -X ...)

相关内容