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,138
  • 25
  • 36
  • 47
mommomonthewind
  • 123
  • 1
  • 6
  • Loook into `nohup` and `tmux` - they do different things, but both will achiave what you're after here. – Attie Jul 03 '18 at 12:50

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,350
  • 2
  • 14
  • 21
Sunil Bhoi
  • 66
  • 5
  • ``screen`` does not work if I restart my laptop I think – mommomonthewind Jul 03 '18 at 12:50
  • You need to run `screen` on the server, not your laptop – Attie Jul 03 '18 at 12:51
  • do you want to run a task on remote server or on your local laptop? These steps are for server. You need to ssh your server follow the steps. So command will be executing on server even if you terminate ssh session. – Sunil Bhoi Jul 03 '18 at 12:52
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
  • 9,782
  • 4
  • 20
  • 31
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
  • 681
  • 8
  • 19