Thursday, March 27, 2008

A couple of Bash tips

  1. Single instance
    # make use of bash `set -C'
    (set -C; : > $lockfile) 2>/dev/null
    if [ $? -ne 0 ]; then
      log_msg "$0 already running, exit"
      exit 0
    fi

  2. Daemonize script
    # `-d' option indicates to daemonize
    if [ x"$1" = "x-d" ]; then
      $0 2>&1 >/dev/null &
      exit 0
    fi

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home