1

I'm a big fan of the linux program "screen" which allows me to start a screen within a SSH session which can stay alive after I disconnect. More info about screen here

Is there a way I can start a screen session from a command line that automatically starts another program (or .sh script) within that screen session?

I'd like to add this to my raspberry pi's boot sequence so that there's always a screen running automatically running some software, even if the pi is restarted, so that I can ssh into the pi at any time to see that software's output.

I have looked at this solution, but this only helps partially. It starts screen like this

screen -t "df" watch -n 10 df

and successfully starts the "df" command.

However when the program is done running, the screen closes and disappears.

I would like the screen to stay alive even if the program originally started is finished.

2 Answers 2

2

Change the command to:

screen -t "df" bash -c 'watch -n 10 df; exec bash'

bash -c : Use bash -c to run multiple commands.

exec bash : After df command terminates, it will start a shell (bash) that won't exit until something external terminates it.

0

You would do this by running the commands in a shell which stays running after the command completes.

For instance, in Prevent GNU screen from terminating session once executed script ends, the accepted answer does an

exec bash

after the command, to start a shell when the command completes.

You must log in to answer this question.

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