xref: /original-bsd/usr.bin/calendar/calendar.sh (revision 2301fdfb)
1#!/bin/sh -
2#
3# Copyright (c) 1988 Regents of the University of California.
4# All rights reserved.  The Berkeley software License Agreement
5# specifies the terms and conditions for redistribution.
6#
7#	@(#)calendar.sh	4.7 (Berkeley) 03/27/88
8#
9PATH=/usr/lib:/bin:/usr/bin:/usr/ucb:/lib	# order important
10
11tmp=/tmp/cal0$$
12trap "rm -f $tmp /tmp/cal1$$ /tmp/cal2$$"
13trap exit 1 2 13 15
14calendar >$tmp
15
16if [ $# = 0 ]; then
17	trap "rm -f $tmp ; exit" 0 1 2 13 15
18	(cpp calendar | egrep -f $tmp)
19	exit 0
20fi
21
22if [ $# = 1 ] && [ $1 = "-" ]; then
23	trap "rm -f $tmp /tmp/cal1$$ /tmp/cal2$$; exit" 0 1 2 13 15
24	echo -n "Subject: Calendar for " > /tmp/cal1$$
25	date | sed -e "s/ [0-9]*:.*//" >> /tmp/cal1$$
26	sed '
27		s/\([^:]*\):.*:\(.*\):[^:]*$/y=\2 z=\1/
28	' /etc/passwd \
29	| while read x
30	do
31		eval $x
32		if test -r $y/calendar
33		then
34			(cpp $y/calendar | egrep -f $tmp) 2>/dev/null > /tmp/cal2$$
35			if test -s /tmp/cal2$$
36			then
37				cat /tmp/cal1$$ /tmp/cal2$$ | mail $z
38			fi
39		fi
40	done
41	exit 0
42fi
43
44echo "usage: calendar [-]"
45exit 1
46