nohup



  • I learned this recently πŸ˜•

    apparently there is this command

     nohup command-with-options &
    

    Nohup is very helpful when you have to execute a shell-script or command that take a long time to finish. In that case, you don’t want to be connected to the shell and waiting for the command to complete. Instead, execute it with nohup, exit the shell and continue with your other work. Cause it is true I recall I did the background & and it was not reliable I reckon it would exit with your session.



  • Yup, I use that easily thirty times a day πŸ™‚ You'll find your output in nohup.out, too.



  • Good reminder @Emad-R !

    I use screen a lot.

    Allows multiple sessions inside one ssh session. And allows you to reconnect to those sessions at a later time. So it can also be used for stuff that takes a long time to complete.

    Usage:

    screen
    

    then do what you want to do, if it takes to long and you cancel the ssh or the ssh session is aborted, then reconnect next time you login with:

    screen -x
    

    Shortcuts:

    • Start another session while working: Ctrl-A + c
    • Switch to first session: Ctrl-A + 0
    • Switch to second session: Ctrl-A + 1
    • Switch to third session: Ctrl-A + 2
    • etc etc

    Man page:
    https://linux.die.net/man/1/screen



  • I'm a big fan of nohup.



  • @Pete-S said in nohup:

    Good reminder @Emad-R !

    I use screen a lot.

    Allows multiple sessions inside one ssh session. And allows you to reconnect to those sessions at a later time. So it can also be used for stuff that takes a long time to complete.

    Usage:

    screen
    

    then do what you want to do, if it takes to long and you cancel the ssh or the ssh session is aborted, then reconnect next time you login with:

    screen -x
    

    Shortcuts:

    • Start another session while working: Ctrl-A + c
    • Switch to first session: Ctrl-A + 0
    • Switch to second session: Ctrl-A + 1
    • Switch to third session: Ctrl-A + 2
    • etc etc

    Man page:
    https://linux.die.net/man/1/screen

    screen is the one I've always used too. I wasn't aware of nohup.



  • This is what I do when I use nohup.
    I usually create a file with the current pid just in case I need to stop it.

    nohup wget 'https://example.com/fedora.iso' > wget_fedora.log 2>&1 &
    echo $! > wget_fedora_pid.txt
    
    kill -9 `cat wget_fedora_pid.txt`
    rm wget_fedora_pid.txt