0

I ran a script from the command line today (php, not sure that matters) which has output I wanted to watch but I had to go home before it finished and I couldn't figure out how to exit without killing the script. Normally I just close the laptop (hibernate) but it doesn't appear the script finished.

Is there some keyboard combination I can hit to exit the terminal and leave the script running? It prints a log file too so I can just check it later.

Braiam
  • 35,991

1 Answers1

2

The most straightforward method to have your scripts continue after you close out of a shell session is to use a terminal multiplexer program. A terminal multiplexer will allow you to run multiple shell sessions concurrently without being actively connected to each one, even after you disconnect (detach) from them. The 2 most popular ones are screen and tmux.

I personally use screen and it works extremely well for me. You start a screen session, start your program/script, disconnect(detach), then reconnect to the detached session later on to see how things went.

To install:

sudo apt-get install screen

To start a session:

screen  

To disconnect (detach) from the session:

Ctrl+A then d

To list running sessions:

screen -ls

To reconnect to a detached session, use the output from screen -ls

screen -r [pid.tty.host]

These are just the basics to get you going, but like always, man screen has much more info

Creek
  • 5,062