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,380
  • 25
  • 108
  • 167
user2344668
  • 167
  • 1
  • 3

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,002
  • 1
  • 22
  • 33
  • `screen` is awesome; [tmux](http://tmux.sourceforge.net/) may be more useful, as it's more customizable. – ILMostro_7 Jun 17 '14 at 07:26
  • Note that `byobu` is not a “third” choice, it's more like a wrapper; it needs either `screen` or `tmux` to run (it was originally based on `screen`) and extends display and features. – Qeole Jun 17 '14 at 11:42
  • @Qeole wasn't aware of that, will update. Thanks – Creek Jun 17 '14 at 11:47