Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a batch script that starts a java server application inside of a screen. The command looks like this:

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

After I run the batch script, it starts the server and puts it inside the correct screen. If I list my screens after, I see something like this:

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

However, I have a second batch script that sends automated commands to this server and runs on a different crontab interval. Because of the way the application works, I send commands to it like this (this command tells it to alert connected users "testing 123"):

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

I've also tried:

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

Unfortunately, these commands DO NOT WORK. They don't even give me an error message, they just do nothing.

HOWEVER - If I manually attach to the screen first (with the below command) and then detach, now I can run any of the above commands flawlessly. I can demonstrate this with a video, if I wasn't clear enough here.

screen -r -d

Thanks in advance.

Update: here is the important parts of /etc/screenrc. It should be totally vanilla, I've never edited this file.

# 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 "^["
share|improve this question
1  
Have you got password protected session? –  Ency Feb 13 '11 at 21:25
    
I don't believe so. I attempted to open ~/.screenrc to check this and found that I do not have a ~/.screenrc file. Is this a problem? Or is that normal? –  James Watt Feb 13 '11 at 23:07
    
Instead of using screen to start a service, wouldn't it be easier to write a standard init script? –  ℝaphink Feb 16 '11 at 7:45

1 Answer 1

up vote 1 down vote accepted

Sadrul on #screen (Freenode) gave this answer, and it worked:

with the -X commands, try specifying the window number as well (e.g. screen -p0 -X ...)

share|improve this answer
    
Excellent! Wasted almost two days before I've finally found this... –  vines Dec 11 '11 at 19:35
    
Glad it helped someone else! –  James Watt Jan 12 '12 at 15:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.