Screen. Run a script on startup in a detached screen

The screen utility provides a way to run a command on a Linux system and then detach from it. This is a particularly useful command if you have a long-running process that you want to keep running even after you log out and still have the ability to reattach to it later and/or from another location.


How to use ‘screen’ command on Linux systems

There are many good tutorials available on the web describing the use of screen, check the references to find some good ones.


I want to show you here only a basic usage of screen, only to run a script on a machine like a server or a Raspberry Pi.


The first step is to install screen on the machine:

$ sudo apt install screen # ubuntu based distro

$ sudo dnf install screen # fedora distro

Here the case of the script So, edit the startup rc.local file:

$ sudo vi /etc/rc.local

And add the following line before the ‘exit 0′ command.

# Run a command as `username` from the home folder
su - username -c "screen -dm -S ~/"

Remember that the script must be set to executable:

$ chmod +x ~/

Reboot the machine and check the script running with:

$ screen -DR

If the machine is a remote machine, you need to ssh to.



Screen User’s Manual –

In Unix, what is screen, and how do I use it? –

How do I use screen on the Linux systems? –