Skip to content

Instantly share code, notes, and snippets.

@mvsantos
Last active February 26, 2019 22:33
Show Gist options
  • Save mvsantos/394054ce8115e7a24298876a358ac676 to your computer and use it in GitHub Desktop.
Save mvsantos/394054ce8115e7a24298876a358ac676 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Immediately exit this script if ..
# any internal command exits with non-zero status
set -o errexit
# any unbound variables are used
set -o nounset
# any pipe fails
set -o pipefail
# Helper functions: logmsg and end_script
# Helper variables:
# __PID__ This script's process ID
# __DIR__ This script's directory i.e. /foo/bar
# __BASE__ This script base name without the ".sh" extension. i.e. baz
# __FILE__ Absolute path this file i.e. /foo/bar/baz.sh
# __TAG__ Stripped down version of __BASE__ . Slug-like string.
__PID__=$$
__DIR__="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__BASE__="$(basename "${BASH_SOURCE[0]}" .sh)"
__FILE__="${__DIR__}/$(basename "${BASH_SOURCE[0]}")"
__TAG__="$(echo "${__BASE__}" | sed 's/[^a-zA-Z0-9_]/\-/g; s/^-*//g; s/-*$//g; s/--/-/g;')"
PID_FILE="${__TAG__}.pid"
for D in /var/run /var/local/run /tmp;
do
if [[ -w ${D} ]]; then
export PID_FILE="${D}/${__TAG__}.pid"
break
fi
done
arg1="${1:-bob}"
echo "arg1=|$arg1|"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment