Score:1

Running a command inside a gnu screen from a bash script

US flag

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?

Score:4
vn flag

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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.