LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Screen, Have to attach before finishing script (https://www.linuxquestions.org/questions/programming-9/screen-have-to-attach-before-finishing-script-872463/)

themattbeballin 04-01-2011 04:45 PM

Screen, Have to attach before finishing script
 
Hello there.

I've been working on a script for my Minecraft servers for a auto backup.

Well, when the server starts... It issues the following command...

Code:

screen -dmS BUKKIT1 /home/minecraft/BUKKIT1/minecraft.run
THEN... I have to attach the screen and detach it to make the rest of the script work... and I need a way around it, since this is automated, and I don't always tend to the machine...

This is the first command the backup script issues to the screen session:

Code:

screen -drS BUKKIT1 -X stuff "say SERVER BACKUP STARTING. Server going read only ..."`echo -ne '\015'`
What that does, is that it posts a message to the minecraft multiplayer saying "SERVER BACKUP STARTING. Server going read only ..."

But if I attach the screen session, then ^a d (CTRL+a d) it works fine.

I've done some searching, but I'm afraid I might not have been searching the correct terms, since I can't find a fix. There may not be one as well, but I figured someone has figured it out by now.

The server is running Arch Linux - Rolling Release, Kernel 2.6.37. Screen version Screen version 4.00.03 (FAU) 23-Oct-06.

Any help with this would be great.

theNbomr 04-01-2011 05:10 PM

There is a long-standing problem with screen, in that it cannot accept commands ('-X stuff', for example) unless it has first been in attached mode. This is troublesome if it must be used in a system startup script, where the is no user to start the screen, and therefore no tty to which it can attach. I have contrived a very cumbersome solution to this problem, and it really isn't pretty.

First, launch an X virtual framebuffer (Xvfb). Then, use the Xvfb as the X server in which to launch an xterm. In the xterm, launch a screen session. Now, since the screen session is in 'attached' mode, you are free to stuff all the commands you like. You can attach to the session at any time later with a terminal connected to a real X server. I run all of this out of /etc/rc.local It helps to put some two or three second sleeps after each step, because things that take some time have to happen, like the virtual X server has to sort out where it finds fonts, bash has to go through some startup, etc.

--- rod.


All times are GMT -5. The time now is 08:48 AM.