Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question About Screen Command

    I run a game server for a game called Minecraft, and its all running through a Linux (CentOS 5.5) VPS. I have the server set up perfectly. I run hourly backups of the server map (you don't need to know what that is), and I use an executable shell file to do so. My current one is:

    screen -x server -X stuff `printf "save-all\r"`
    sleep 2
    cd server
    cd pandaland
    zip `date "+%Y-%m-%d-%H-%M-%S"`.zip -r ./* -x \*.zip
    This sends the printf command to the (detached) screen that it's running in, and executes the command (for the game) called 'save-all'. That is working correctly. However, when I use the same command like so:

    screen -x server -X stuff `printf "say testing\r"`
    (The command for the server console here is 'say <message>', which outputs a message to all players in the server)

    Nothing happens. I suspect that it is a problem with the spaces inside the command, but I can't get anything to work.

    I then noticed that this code:

    screen -x server -X stuff '<command>'
    Actually prints the <command> (in this case, 'say testing') into the console, but doesn't execute it. It needs to send the enter key (what I assume here to be a newline key).

    Anyone know what I should do?

  2. #2
    Linux User
    Join Date
    Nov 2008
    Tokyo, Japan
    Are you absolutely sure you need to output a "\r" and not a "\n", or perhaps both "\n\r"? The "echo" command does "\n" for you, so you don't need printf for that. You could also try this:
    screen -x server -X stuff $(printf "say testing\r")
    This does the same thing as the back-quotes, except it might handle cascading variables differently (I actually don't know) -- it is just something you can try.

    Also, when using "printf", it is better to use single-quotes instead of double-quotes because single-quotes do not expand special characters.
    screen -x server -X stuff $(printf 'say testing\r')
    Check the bash manual for more information on the difference between single and double quotes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts