[net.sources] Cute

ron@men1.UUCP (Ron Flax) (01/10/85)

This is a cute little program to put in a uses .login or .profle file
to welcome him/her differently at different times of the day.


The program is called tod.c (time of day):

------C-U-T--H-E-R-E------------------------C-U-T--H-E-R-E--T-O-O------
#include <stdio.h>
#include <time.h>

struct tm  *localtime ();
struct tm  *loc_time;

main ()
{
   long clock;
   char tod[5];
   int t_hour, t_min, daytime, tnum;
   static char *daymsg[] = {"Good Morning!", 
    		      	    "Good Afternoon! Only a few more hours to go.",
		      	    "Good Evening! Working late I see.",
		      	    "Good Grief! What are you doing on at this hour?",
			    "I don't know what time it is, do you?"};

        time (&clock);
        loc_time = localtime (&clock);
        t_hour = loc_time->tm_hour;
        t_min  = loc_time->tm_min;
	sprintf (tod, "%2d%02d", t_hour, t_min);
	daytime = 5; 		/* Not sure what time it is? */
	tnum = atoi (tod);
	if (tnum >= 0500 && tnum <= 1159)  /* it's morning */
		daytime = 0;
	if (tnum >= 1200 && tnum <= 1759)  /* it's afternoon */
		daytime = 1;
	if (tnum >= 1800 && tnum <= 2359)  /* it's evening */
		daytime = 2;
	if (tnum >= 0000 && tnum <= 0459)  /* it's late! */
		daytime = 3;
	printf ("\n\7%s\n", daymsg[daytime]);
}
------C-U-T--H-E-R-E------------------------C-U-T--H-E-R-E--T-O-O------

Ron@men1	(Ron Flax)
MTACCS Engineering Network
..!{seismo,umcp-cs}!{prometh,cal-unix}!men1!ron

chris@umcp-cs.UUCP (Chris Torek) (01/12/85)

Gee, we force this one on everyone here!  We have in /usr/lib/crontab
the line

	2 0,6,12,18 * * * /usr/local/etc/motd_ed

with the motd_ed script reading:

	#! /bin/csh -f
	set file=/tmp/med_$$
	cat <<'fin' >$file
	g/Good morning!/d
	g/Good afternoon!/d
	g/Good evening!/d
	g/What are you doing on at this time of night?/d
	$-1a
	'fin'
	set time=`date | awk '{printf $4}' | awk -F: '{print $1}'`
	if ($time < 6) then
		echo 'What are you doing on at this time of night?' >>$file
	else if ($time < 12) then
		echo 'Good morning\!' >>$file
	else if ($time < 18) then
		echo 'Good afternoon\!' >>$file
	else
		echo 'Good evening\!' >>$file
	endif
	cat <<'fin' >>$file
	.
	w
	q
	'fin'
	ex - /etc/motd <$file
	rm $file

(We also have /etc/rc.local invoke this to fix the motd when rebooting.)
-- 
(This line accidently left nonblank.)

In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland