h_12
h_12

Reputation: 31

bash script for screen -r

I want to make a bash script that echo's something into one of the screens that I have running (screen -r is how I get to it in SSH).

I was wondering how I would make the script execute itself in screen -r?

I basically just want the script to say something on a minecraft server through the console and would set up a cronjob to say it every x minutes.

Cheers,

Upvotes: 1

Views: 627

Answers (2)

frosch03
frosch03

Reputation: 729

You can use the -X option of screen to send commands to a running screen session. Also the -p option is useful in this case, as you can use it to preselect a window

As an example you can run a script in a running screen session on windows 0 via:

 screen -p 0 -X stuff './fancy_script.sh^M'

Note, that you have to append the return key-code to execute the script.

Upvotes: 2

Marc Plano-Lesay
Marc Plano-Lesay

Reputation: 6958

You can look in /dev/pts. I don't have screen here to test, but you can echo something to an opened terminal with, for example, echo "toto" > /dev/pts/0 (it will be echoed on the first opened terminal).

Upvotes: 0

Related Questions