detach.sh 340 B

123456789101112131415
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. temp="/tmp/launch"
  4. mkdir -p "$temp"
  5. logfilename="${1##*/}_$(date +%F_%H%M%S_%N)"
  6. stdout="${temp}/${logfilename}_stdout.log"
  7. stderr="${temp}/${logfilename}_stderr.log"
  8. echo "== LAUNCH ${*} ==" > "$stdout"
  9. echo "== LAUNCH ${*} ==" > "$stderr"
  10. nohup "$@" >>"$stdout" 2>>"$stderr" &