#!/usr/bin/env etsh : : etsh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; : : " @(#)$Id: 2e0cf35531ac2f19d9222ba1ad54785135d5b8c7 $ " : : " The author of this file, J.A. Neitzel , " : " hereby grants it to the public domain. " : : : " Cause the user's terminal to act as an alarm clock by repeatedly " : " ringing the terminal bell at the specified time until the user " : " snoozes it or turns it off. " : : " usage: ( alarm CCYYMMDDhhmm & ) " : " or: " : " usage: alarm CCYYMMDDhhmm & " : " or: " : " usage: alarm [help | off | snooze] " : umask 0077 setenv TZ EST5EDT ; : " Choose your time zone. " if ! -e $h/.alarm -a ! -h $h/.alarm if ! { mkdir $h/.alarm } if { exit } false if ! -d $h/.alarm -o -h $h/.alarm if { exit } perror $0 $h/.alarm'": Not a directory"' chdir ; chdir .alarm : : " Check for correct usage. " : : >>$0'' <'' ; : >>$1'' <'' ; killer $0 alarm if $# = 0 goto Status if X$1 = Xhelp goto Usage if X$1 = Xoff goto Off if X$1 = Xsnooze goto Snooze if ! { \ expr \ //$1 : \ '//[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*' = 14 \ \& \ //$1 : \ '//[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*' = \ //$1 : '//.*' \ } goto Usage >/dev/null goto Continue : Usage fd2 -e -- head -5 ; false ; exit usage: ( alarm CCYYMMDDhhmm & ) or: usage: alarm CCYYMMDDhhmm & or: usage: alarm [help | off | snooze] : Continue if -e alarm if { exit } perror $0 '"Already running."' if X$t != X goto Usage : : " Set everything up as needed... " : trap : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ( : " Fail if this process does not have a controlling terminal. " ) >/dev/tty rm -f off snooze status timer alarm if ! { touch -t $1 alarm } if { exit } false date '+%Y%m%d%H%M%S' >timer if timer -nt alarm rm -f alarm if ! -e alarm if { exit } perror $0 '"Cannot ring alarm in the past."' : : " Create the status script for this alarm process. " : ( \ echo "echo "$$" | sed 's,^0*\(.*\),ps -p\1,' | etsh - | \ sed 1d | wc -c | tr -d ' \t' | grep '^0$' >/dev/null" ; \ echo 'if $? = 0 if { exit } false' ; \ echo "echo "$$" | sed 's,^0*\(.*\),ps -p\1,' | etsh - ; :" ; \ ) >status : Timer if ! \( -t 1 -a -t 2 \) goto Off sleep 60 ; date '+%Y%m%d%H%M%S' >timer if timer -ot alarm goto Timer if -e off goto Off rm -f snooze : fallthrough : Alarm if ! \( -t 1 -a -t 2 \) goto Off bell 5 0.2 ; sleep 1 if -e snooze if { sleep 600 } rm -f snooze if ! -e off goto Alarm : fallthrough : Off rm -f snooze status timer alarm ; date '+%Y%m%d%H%M%S' >off ; exit : Snooze if -e snooze if { exit } perror $0 '"Already snoozing."' if ! -e status if { exit } perror $0 '"Not running."' if ! { etsh status >/dev/null } if { exit } perror $0 '"Not running."' if timer -ot alarm \ if { exit } perror $0 '"Cannot snooze until alarm rings."' date '+%Y%m%d%H%M%S' >snooze exit : Status if ! -e status if { exit } perror $0 '"Not running."' if ! { etsh status } if { exit } perror $0 '"Not running."' : zero status