#!/bin/bash # written by Peter Selinger, modified 2004/01/24 # Turn the beeper on/off: this is used as a low battery warning. # Must be called with argument "on" or "off". # configuration LOCKFILE=/var/run/beeper.pid beep () { while true; do echo -n $'\007' >> /dev/console sleep 1 done } case "$1" in on | start ) if [ -e "$LOCKFILE" ]; then lockid=`cat "$LOCKFILE"` if [ -e /proc/$lockid ] && grep -q beeper.sh /proc/$lockid/cmdline; then exit 0 else echo "Removing stale lock for PID $lockid." rm -f "$LOCKFILE" fi fi echo "Starting beeper..." beep & echo $! > $LOCKFILE ;; off | stop ) if [ -e "$LOCKFILE" ]; then lockid=`cat "$LOCKFILE"` if [ -e /proc/$lockid ] && grep -q beeper.sh /proc/$lockid/cmdline; then echo "Stopping beeper..." # Note: -KILL is needed, else the process will not stop kill -KILL "$lockid" rm -f "$LOCKFILE" else echo "Removing stale lock for PID $lockid." rm -f "$LOCKFILE" fi fi ;; * ) echo "Usage: $0 [on|off]" > /dev/stderr exit 1 ;; esac