How to leave a task behind on the server to run

Recently, I need to run a huge crawling tasks on the server side, and since I couldn’t leave my ssh connection on and run the task for 100 hours, what if I tripped over the router and got discounnected?

So I considered delayed_job on Rails, but I ran into some problems that I couldn’t solve, so I found another work around to this problem which might be useful in other cases. The solution is using tmux or screen:

http://stackoverflow.com/questions/11190648/how-to-keep-rails-command-from-rails-console-running-after-ssh-client-putty-cl

Here’s how to do it:

  1. ssh into_your_server
  2. tmux
  3. (you should see the tmux screen)
  4. execute whatever you want to run here
  5. press Ctrl-b then d
  6. (you should be detached from the tmux now)
  7. ps aux |grep tmux (you should be able to see tmux is still running your task)
  8. (reattach with your task by) tmux attach-session
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s