[alt.sources] Show pending jobs in HDB uucp

local@crdos1.crd.ge.COM (local software) (10/30/90)

  After a job comes in via uucp, and before it is run via uuxqt, it is
in a state I call "pending." When debugging a system, or just looking
around, I like to see what's there. Here's my program to do that. Also
useful when tuning the system to determine how often to run uuxqt from
cron.

#!/bin/sh
# shar:	Shell Archiver  (v1.29)
#
#	Run the following text with /bin/sh to create:
#	  pending.1
#	  Makefile
#	  pending.c
#
sed 's/^X//' << 'SHAR_EOF' > pending.1 &&
X.TH pending 1 Local
X.SH NAME
Xpending \- list jobs pending from a remote site
X.SH SYNOPSIS
Xpending remotesite
X.SH DESCRIPTION
XThe \fBpending\fP command shows jobs received from a remote site which
Xhave not yet been processed by uuxqt. There are jobs which will be
Xexecuted locally at some future time.
X.SS INSTALLATION
XThis program will only run from the uucp user (unless you security is
X\fIvery\fP lax), but may be installed setuid to uucp.
X.SH EXAMPLES
X  $ pending maxxwell
X
X     Job             User            Input File      Task
X    crdgw1X0T9Q     root crdgw1     D.crdgw1b0T9S   rmail stugr02!bob
X.SH FILES
X/usr/spool/uucp/site/*
X.SH SEE ALSO
Xuustat
X.SH DIAGNOSTICS
XCan't get working dir - invalid site name of no directory for this site.
XCan't start ls - too many processes or /bin/ls missing.
XCan't open info file - sync error, uuxqt running, or access denied.
X.SH LIMITATIONS
XOnly works for HDB uucp.
X.SH AUTHOR
XBill Davidsen, davidsen@crdos1.crd.ge.com
X.SH Copyright
XCopyright (c) 1988,1990 by Bill Davidsen, All rights reserved. This
Xprogram and documentation may be freely distributed and used providing
Xthe copyright notices are kept intact.
SHAR_EOF
chmod 0666 pending.1 || echo "restore of pending.1 fails"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X# makefile for pending command
X
X# ================> check everything below this line
X
XCFLAGS		= -O
XLFLAGS		= -S
X# remember to use /usr/man/man.LOCAL for SCO
XMANDIR		= /usr/man/man1
X# This is where you install it, like /usr/lbin, /usr/local/bin, 
X# /local, /u/local/bin or /usr/bin as last resort.
XBINDIR		= /u/local/bin
X# your local shar program
XSHAR		= shar
X
X# ================> stop, you've checked enough
X
XBASEFILES	= pending.1 Makefile
XSHARLIST	= $(BASEFILES) pending.c
XSHAROUT		= pending.shar
X
X# magic makerule for SCCS
X.c~.c:
X	get $<
X
X# default
Xdefault:
X	@echo "After you have checked the first few lines of the Makefile"
X	@echo "you can type \"make pending\" or \"make install\"."
X	@echo "You can \"make clean\" after the install is done."
X
Xpending: pending.o
X	$(CC) -o pending $(LFLAGS) pending.o
X
Xinstall: pending pending.1
X	cp pending $(BINDIR)/pending
X	chusr uucp $(BINDIR)/pending
X	chmod 4711 $(BINDIR)/pending
X
Xshar: $(SHAROUT)
X$(SHAROUT): $(SHARLIST)
X	$(SHAR) $(SHARLIST) > $(SHAROUT)
X
Xclean:
X	rm -f pending $(SHAROUT)
X	test -f p.pending.c || rm -f pending.c
X
X# this is for the author!
Xzoo: pending.zoo
XZOOLIST		= $(BASEFILES) s.pending.c
Xpending.zoo: $(ZOOLIST)
X	zoo aunM pending.zoo $?
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
sed 's/^X//' << 'SHAR_EOF' > pending.c &&
X/* list pending HDB requests from a site */
X
X#include <stdio.h>
X
X#define HDBdir	"/usr/spool/uucp"
X#define EOS		'\0'
X
Xstatic char *IDent[] = {
X	"@(#)pending.c v1.2, 10/29/90"
X	"Copyright 1988 by Bill Davidsen, all rights reserved",
X	"May be freely distributed and used providing copyright",
X	"notices are kept intact."
X};
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X	char dirname[1024], filename[32], dataline[132];
X	char xfilename[32], wkfilename[132], *DummY = IDent[0];
X	int slen;					/* string length */
X	int first1 = 1;				/* flag for 1st time thru */
X	FILE *lsout, *popen(), *xfile, *fopen();
X
X	/* test input */
X	if (argc != 2) {
X		fprintf(stderr, "Format:\n  pending SYSname\n\n");
X		exit(1);
X	}
X
X	sprintf(dirname, "%s/%s", HDBdir, argv[1]);
X	if (chdir(dirname)) {
X		perror("Can't get working dir");
X		exit(1);
X	}
X	
X	lsout = popen("ls X.* 2>&1", "r");
X	if (lsout == NULL) {
X		perror("Can't start ls");
X		exit(1);
X	}
X
X	filename[31] = EOS;
X	/* loop checking files */
X	while (fgets(filename, 31, lsout)) {
X		if (strlen(filename) > 30) {
X			fprintf(stderr, "filename too long\n");
X			exit(1);
X		}
X
X		/* see if there's a file found */
X		sscanf(filename, "%s", xfilename);
X		if (strncmp(xfilename, "X.*", 3) == 0) {
X			fprintf(stderr, "No jobs pending\n");
X			exit(0);
X		}
X
X		/* open the file for reading */
X		xfile = fopen(xfilename, "r");
X		if (xfile == NULL) {
X			perror("Can't open info file");
X			exit(1);
X		}
X
X		/* check for header needed */
X		if (first1) {
X			first1 = 0;
X			printf("\n %-15s %-15s %-15s %s\n",
X				"Job", "User", "Input File", "Task");
X		}
X
X		/* scan the file for various things */
X		printf("%-15s ", xfilename+2);
X		dataline[131] = EOS;
X		while (fgets(dataline, 131, xfile)) {
X			if ((slen = strlen(dataline)) > 130) {
X				/* line too long */
X				while (getc(xfile) != '\n');
X			}
X			dataline[slen-1] = EOS;
X
X			switch (dataline[0]) {
X			case 'U': /* originating user */
X				printf("%-15s ", dataline+2);
X				break;
X			case 'C': /* command */
X				printf("%s\n", dataline+2);
X				break;
X			case 'I': /* input file */
X				printf("%-15s ", dataline+2);
X				break;
X			}
X		}
X
X		/* clean up */
X		fclose(xfile);
X	}
X
X	pclose(lsout);
X	exit(0);
X}
X/* tabs=4 */
SHAR_EOF
chmod 0444 pending.c || echo "restore of pending.c fails"
exit 0