我有一个批处理脚本,在屏幕内启动一个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间隔。 由于应用程序的工作方式,我发送命令给它(这个命令告诉它提醒连接的用户“testing123”):
screen -X exec .\!\! echo say testing 123
我也试过:
screen -R -X exec .\!\! echo say testing 123 screen -S javascreen -X exec .\!\! echo say testing 123
不幸的是,这些命令不起作用。 他们甚至不给我一个错误信息,他们什么都不做。
然而,如果我手动连接到屏幕(使用下面的命令),然后分离,现在我可以完美地运行上述任何命令。 如果我在这里不够清楚,我可以用video来certificate这一点。
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 "^["
#screen(Freenode)上的Sadrul给出了这个答案,它的工作原理是:
使用-X命令,尝试指定窗口号(例如screen -p0 -X …)