0

This question already has an answer here:

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.

marked as duplicate by jasonwryan, Mat, Caleb, slm, Jenny D Jun 17 '14 at 9:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

  • screen is awesome; tmux may be more useful, as it's more customizable. – ILMostro_7 Jun 17 '14 at 7: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

Not the answer you're looking for? Browse other questions tagged or ask your own question.