#!/bin/sh # Uncomment the following line to get debug info #set -x SELF="$(basename ${0})" PID_FILE="/var/run/funkey.pid" usage() { >&2 echo "Usage: ${SELF} record pid" >&2 echo " ${SELF} erase" >&2 echo " ${SELF} print" exit 1 } record_pid() { local pid="${1}" if ! [ ! "${pid}" -ne "${pid}" ]; then >&2 echo "error: ${pid} is not a number" exit 2 fi echo "${1}" > "${PID_FILE}" } erase_pid() { rm -f "${PID_FILE}" } case "${1}" in record) if [ ${#} -ne 2 ]; then usage fi record_pid "${2}" ;; erase) if [ ${#} -ne 1 ]; then usage fi erase_pid ;; print) cat "${PID_FILE}" ;; *) usage ;; esac exit 0