linux - How to keep remote script running when dropping ssh?

02
2013-08
  • ohho

    I ssh from my MacBook to a remote Linux and started a lengthy script (import 2000000+ lines of csv text records into MySQL). Too bad I have to take away my MacBook one hour later.

    How can I keep the script running when I unplug my MacBook?

  • Answers
  • Nifle

    Use nohup and run your process in the background. Run your process like this:

    nohup command &

    Edit:
    To nohup running processes: press ctrl+z, enter "bg" and enter "disown"

  • simonp

    nohup is fine, but spartian. screen is powerful. Let's do:

    screen
    command
    

    type Control-A, then d. This will detach the screen session. You'll see the detached session with:

    screen -ls
    

    To reattach a session:

    screen -r
    

    See also this screen presentation


  • Related Question

    osx - How do you run a SSH server on Mac OS X?
  • J. Pablo Fernández

    How do you run a ssh server on Mac OS X?


  • Related Answers
  • J. Pablo Fernández

    Go to System Preferences -> Sharing, enable Remote Login.

  • Nicholaz

    In System Preferences under Sharing is an option for "Remote Login".

    This will run sshd at startup (through the launch-daemon) and enable SSH access with standard options. To tweak the sshd options, edit /etc/sshd_config (you'll need to do this in a sudo shell or via "sudo vi /etc/sshd_config").