linux – 屏幕-X exec命令直到手动连接才能工作

前端之家收集整理的这篇文章主要介绍了linux – 屏幕-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 "^["

解决方法

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

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

猜你在找的Linux相关文章