#!/usr/bin/env osh : : osh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; : : " @(#)$Id: 4a1b27829c8e797e5ba5bfe2570b7561c092d707 $ " : : " 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. This command file may be invoked " : " either as a background process (preferred) or as a foreground " : " process according to the needs of the user. " : : " usage: alarm [CCYYMMDDhhmm | off | snooze] " : umask 0077 setenv TZ EST5EDT ; : " Choose your time zone. " if ! -e $h/.alarm if ! { mkdir $h/.alarm } if { exit } false chdir ; chdir .alarm : : " Check for correct usage. " : : >>$0'' <'' ; : >>$1'' <'' ; killer $0 alarm if $n = 0 goto Status 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 : '//.*' \ } if { exit } pusage $0 '"[CCYYMMDDhhmm | off | snooze]"' >/dev/null if -e alarm if { exit } perror $0 '"Already running."' : : " Set everything up as needed... " : sigign + 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,' | osh - | \ sed 1d | wc -c | tr -d ' \t' | grep '^0$' >/dev/null" ; \ echo 'if $s = 0 if { exit } false' ; \ echo "echo "$$" | sed 's,^0*\(.*\),ps -p\1,' | osh - ; :" ; \ ) >status if X$t = X goto Timer : : " Allow SIGINT, and inform user how to terminate alarm. " : " User should run `alarm off' *after* it terminates... " : sigign - 2 perror $0 '"Type an INTR (^C) to terminate alarm process."' : fallthrough : Timer 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 bell 5 0.2 ; sleep 1 if -e snooze if { sleep 600 } rm -f snooze if ! -e off goto Alarm : fallthrough : Off if ! -e status if { exit } perror $0 '"Not running."' if ! { osh status >/dev/null } if { exit } perror $0 '"Not running."' rm -f 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 ! { osh 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 ! { osh status } if { exit } perror $0 '"Not running."' : zero status