0

Say I have a laptop and an Ubuntu server. There is a heavy task that I want to perform on Ubuntu server.

So far, I connected to the server through SSH and perform it. However, when I need to shut down the laptop (leaving the office), the SSH session is lost and I have no idea what is going on with the process.

Is there a solution that I can let the process run on Ubuntu server, and tomorrow morning when I turn my laptop on I can resume checking what's happening with the process?

Dave M
  • 13,250

3 Answers3

3

Use screen command on server. You need to install related package if not present on server

sudo apt-get install screen
  1. create screen

    screen
    
  2. execute command you want to run in that screen

  3. come out of the screen by pressing Ctrl + a + d

  4. list the screen

    # screen -ls 
    
  5. You can now come of out ssh session as your command is running in screen

  6. ssh again and attach the screen to check the command status

    screen -r screen_name
    
Ahmed Ashour
  • 2,490
2

Start your command with nohup: nohup {command} {args...} and often reroute the output to file:nohup {command} {args...} >{logfile}.

Among other things nohup prevents your command from receiving the SIGHUP signal that tells it its parent disconnected.

If you reconnect and want to check the output, do tail -f {logfile}.

xenoid
  • 10,597
0

I usually run the task in background and log output to files, checking progress by "tailing" my logs:

$> my_long_task.sh > stdout.log 2> stderr.log &

And when I want to check the status I do:

$> tail stdout.log
$> tail stderr.log
DDS
  • 759