How do I run screen and run a command inside of screen automatically?

CosmicWanderer

New Member
Joined
Feb 17, 2026
Messages
12
Reaction score
11
Credits
108
I have a game server that I want to automatically run whenever I start up the physical server. For a while I just used systemd to start the server directly, but this game server has a console that I want to be able to access at runtime. Ideally, I would like to have some sort of setup where a detached screen is created, the program is run, and I can attach the screen when I want to use it. Is that possible and if so, how do I do it?
 


presumably you would need to start the game server as a service and configure it to start on boot, then pipe the output to the terminal or something. no idea really.

a lot more information is needed. what distro? what DE? what game? probably other specific information, this kind of thing is a bit outside of my personal scope of knowledge
 
I have a console based system monitor tool that I can run in a screen session and then access the running session later from a remote login. The program is named "conmon" so...

at boot time I can run

Code:
screen -S conmon conmon

where the "-S conmon" option specifies the session name by which you will access the process from another screen session. (Lacking the "-S conmon" argument, the session name will be something like "<pid>.pts-0.<hostname>" )

To attach to the session later, I log into the server and run

Code:
screen -rd conmon

where -d disconnects any other attached session and -r reconnects it to this session.

I wrote a little wrapper script that takes a program name and, if a screen session exists with that session name, connects to it. If no such session exists, it starts one. It's kind of simplistic, but it was written for a very simple need.
 


Follow Linux.org

Members online


Latest posts

Top