new "gloria"
Jonathan C. Broome
broome at ucbvax.ARPA
Sat Jun 15 07:02:45 AEST 1985
[ yum! ]
This is a new version of a program called "gloria" that was posted to the net
a while back which searches through each user's home directory for a files with
the name specified and modification times later than the last time checked.
Essentially it's like "find / -name 'name' -mtime -"last" -exec cat {} \; ",
only easier to type, and gloria keeps track of "last" for you... The main
differences between this version and the original are: this one allows you
to keep tabs on multiple files, instead of only ".plan"; it has the "-s" option
to suppress printing the file's contents, and it prints control characters in
^X form (we have a lot of people who like to put escape sequences in their
.plan's here!)
Possible portability problems:
1. rindex() in main() - change to strrchr() for USG systems.
2. the method used in do_rc() - you may need to change it to use a temporary
file to do the update, then copy back (or use rename() if you have it)
As usual, send any bugs or improvements to me...
===========================================================
Jonathan C. Broome University of California, Berkeley
UUCP ...!ucbvax!broome
ARPA broome at ucbvax.ARPA
===========================================================
#----cut here-----cut here-----cut here-----cut here-----
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# gloria.1
# gloria.c
# This archive created by broome at Fri Jun 14 13:19:06 1985
export PATH; PATH=/bin:$PATH
if test -f 'gloria.1'
then
echo shar: will not over-write existing file "'gloria.1'"
else
sed 's/^XX//' << \StUnKy_fLuFf > 'gloria.1'
XX.TH GLORIA public
XX.UC 4
XX.SH NAME
XXgloria - search for changed files and print their contents
XX.SH SYNOPSIS
XXgloria [ -s ] \fIfile\fR
XX.SH DESCRIPTION
XX\fBGloria\fR searches through the home directories of each user
XXon the machine for files named \fIfile\fR with modification dates
XXafter the time last recorded in \fI~/.gloria\fR. Unless the \fI-s\fR
XXoption is specified, it will also try to print out the contents
XXof the file.
XX.SH FILES
XX~/.gloria --- contains date of last search for a given filename
XX.SH SEE ALSO
XXfind (1)
XX.SH DIAGNOSTICS
XX"[ Not Accessible ]" when file is unreadable.
XX.SH BUGS
XXShould probably learn about subdirectories and the like.
XX.SH HISTORY
XXFrom a first version posted to net.sources by Michael Mauldin
XXof Columbia University (fuzzy at cmu-cs-c), this version by Jonathan Broome
XX(broome at Berkeley)
StUnKy_fLuFf
if test 814 -ne "`wc -c < 'gloria.1'`"
then
echo shar: error transmitting "'gloria.1'" '(should have been 814 characters)'
fi
fi # end of overwriting check
if test -f 'gloria.c'
then
echo shar: will not over-write existing file "'gloria.c'"
else
sed 's/^XX//' << \StUnKy_fLuFf > 'gloria.c'
XX#include <pwd.h>
XX#include <stdio.h>
XX#include <sys/types.h>
XX#include <sys/time.h>
XX#include <sys/stat.h>
XX
XXchar *prog;
XXchar filename[BUFSIZ]; /* name of file we're interested in */
XXint no_show = 0; /* 1 => don't show contents of file */
XX
XXmain (argc, argv)
XXint argc;
XXchar **argv;
XX{
XX char *r, *rindex();
XX char *ctime();
XX long now, last, do_rc();
XX
XX if (prog = rindex (*argv, '/'))
XX prog++;
XX else
XX prog = *argv;
XX
XXagain:
XX if (--argc == 0) /* no arguments given */
XX usage ();
XX
XX if (strcmp (*++argv, "-s") == 0) { /* short form - just print name */
XX no_show = 1;
XX goto again;
XX }
XX strcpy (filename, *argv); /* and save name of file to look for */
XX
XX time (&now);
XX last = do_rc (filename, now); /* get and update last time checked */
XX printf ("Last checked file %s on %s", filename, ctime (&last));
XX
XX gloria (filename, last); /* and do it */
XX exit (0);
XX}
XX
XX/*
XX * Print a usage message and exit.
XX */
XXusage ()
XX{
XX fprintf (stderr, "Usage: %s [-s] filename\n", prog);
XX exit (1);
XX}
XX
XX/*
XX * Open ~/.gloria and get last date for file ``name'',
XX * then update the old time (or create a new entry)
XX * We use append mode so as to avoid having to do a
XX * file-to-file copy, instead just do each read one
XX * line ahead of each write.
XX */
XX
XXlong do_rc (name, now)
XXchar *name;
XXlong now;
XX{
XX char *getenv();
XX char file[80], buf[80];
XX long when, last = 0L;
XX FILE *rp, *wp;
XX
XX sprintf (buf, "%s/.gloria", getenv ("HOME")); /* open file for append */
XX if ((wp = fopen (buf, "a")) == NULL) { /* so we can read and */
XX fprintf (stderr, "%s: cannot open %s\n", buf);/* write at same time */
XX exit (1); /* (no truncate) */
XX }
XX fseek (wp, 0L, 0);
XX
XX if ((rp = fopen (buf, "r")) != NULL) { /* only if rc file exists */
XX while (fgets (buf, 80, rp)) {
XX sscanf (buf, "%s %ld", file, &when); /* name, last time checked */
XX fputs (file, wp);
XX if (strcmp (file, name) == 0) {
XX last = when;
XX fprintf (wp, " %ld\n", now);
XX } else
XX fprintf (wp, " %ld\n", when);
XX }
XX fclose (rp);
XX }
XX
XX if (last == 0L) /* wasn't in rc file */
XX fprintf (wp, "%s %ld\n", name, now); /* add new entry */
XX fclose (wp);
XX return (last);
XX}
XX
XX
XX/*
XX * Main Gloria loop - look for files whose names match and
XX * have modification times after ``last''.
XX */
XX
XXgloria (name, last)
XXchar *name;
XXlong last;
XX{
XX struct stat statb;
XX struct passwd *pwd, *getpwent();
XX char buf[256];
XX FILE *fp;
XX
XX setpwent (); /* open passwd file */
XX while (pwd = getpwent ()) {
XX sprintf (buf, "%s/%s", pwd->pw_dir, name);
XX if (stat (buf, &statb)) /* no such file */
XX continue;
XX if (statb.st_mtime >= last) {
XX if (no_show) { /* don't show file */
XX printf ("%s\n", buf);
XX continue;
XX }
XX printf ("\n==>> %s's file: (%s) <<== \n", pwd->pw_name, buf);
XX if ((fp = fopen (buf, "r")) == NULL)
XX printf ("[ Not Accessible ]\n");
XX else
XX cat (fp);
XX }
XX }
XX endpwent ();
XX}
XX
XX/*
XX * Show the contents of a file. We play it safe by converting control
XX * characters to ^X form. (People are fond of putting escape sequences
XX * in their .plan files around here!)
XX */
XX
XXcat (fp)
XXFILE *fp;
XX{
XX int ch;
XX
XX while ((ch = getc (fp)) != EOF)
XX if (ch < ' ' && ch != '\t' && ch != '\n')
XX printf ("^%c", ch + '@');
XX else
XX putchar (ch);
XX fclose (fp);
XX if (ch != '\n') /* needs a newline at end */
XX putchar ('\n');
XX}
StUnKy_fLuFf
if test 3464 -ne "`wc -c < 'gloria.c'`"
then
echo shar: error transmitting "'gloria.c'" '(should have been 3464 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0
More information about the Comp.sources.unix
mailing list