Skip to content

Instantly share code, notes, and snippets.

@Galarius
Created October 22, 2016 07:41
Show Gist options
  • Save Galarius/6643c0bc3a145d6b5492a1e4c5386ae7 to your computer and use it in GitHub Desktop.
Save Galarius/6643c0bc3a145d6b5492a1e4c5386ae7 to your computer and use it in GitHub Desktop.
Self-detaching shell script
#!/bin/bash
# self-detach.sh
# Self-detaching shell script
#------------------------------------------
if [ -z "$_DETACHED_" ]
then
# Run this script silently in background
# mode with low priority
_DETACHED_=1 nohup nice sh $0 &>/dev/null
exit 0
fi
#------------------------------------------
# Perform some task here
# ...
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment