1

I'm currently trying to run a command in a detached gnu screen from bash, but simply using

screen -r myscreen
mycommand

doesn't work. Detaching from the screen after executing the command isn't necessary since the command is used to gracefully exit the program.

I also tried using

{ 
  mycommand
} | sudo screen -r myscreen

like answered on the post Bash Script commands inside a program, but this returned Must be connected to a terminal, along with a command not found error.

Is there a way to execute a command in a gnu screen from bash?

0

1 Answer 1

4

From man screen:

   -S sessionname
        When creating a new session, this option can be used to specify a meaningful name for
        the session. This name identifies the session for screen -list and screen -r actions.
        It substitutes the default [tty.host] suffix. This name should not be longer then  80
        symbols.

   -X   Send the specified command to a running screen session. You may use the -S option  to
        specify  the  screen session if you have several screen sessions running. You can use
        the -d or -r option to tell screen to look  only  for  attached  or  detached  screen
        sessions. Note that this command doesn't work if the session is password protected.

So you could use:

screen -S myscreen -X your-command

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .