home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2014 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  5.5 KB

  1. From: local@crdos1.crd.ge.COM (local software)
  2. Newsgroups: alt.sources
  3. Subject: Show pending jobs in HDB uucp
  4. Message-ID: <2801@crdos1.crd.ge.COM>
  5. Date: 29 Oct 90 21:58:30 GMT
  6.  
  7.  
  8.   After a job comes in via uucp, and before it is run via uuxqt, it is
  9. in a state I call "pending." When debugging a system, or just looking
  10. around, I like to see what's there. Here's my program to do that. Also
  11. useful when tuning the system to determine how often to run uuxqt from
  12. cron.
  13.  
  14. #!/bin/sh
  15. # shar:    Shell Archiver  (v1.29)
  16. #
  17. #    Run the following text with /bin/sh to create:
  18. #      pending.1
  19. #      Makefile
  20. #      pending.c
  21. #
  22. sed 's/^X//' << 'SHAR_EOF' > pending.1 &&
  23. X.TH pending 1 Local
  24. X.SH NAME
  25. Xpending \- list jobs pending from a remote site
  26. X.SH SYNOPSIS
  27. Xpending remotesite
  28. X.SH DESCRIPTION
  29. XThe \fBpending\fP command shows jobs received from a remote site which
  30. Xhave not yet been processed by uuxqt. There are jobs which will be
  31. Xexecuted locally at some future time.
  32. X.SS INSTALLATION
  33. XThis program will only run from the uucp user (unless you security is
  34. X\fIvery\fP lax), but may be installed setuid to uucp.
  35. X.SH EXAMPLES
  36. X  $ pending maxxwell
  37. X
  38. X     Job             User            Input File      Task
  39. X    crdgw1X0T9Q     root crdgw1     D.crdgw1b0T9S   rmail stugr02!bob
  40. X.SH FILES
  41. X/usr/spool/uucp/site/*
  42. X.SH SEE ALSO
  43. Xuustat
  44. X.SH DIAGNOSTICS
  45. XCan't get working dir - invalid site name of no directory for this site.
  46. XCan't start ls - too many processes or /bin/ls missing.
  47. XCan't open info file - sync error, uuxqt running, or access denied.
  48. X.SH LIMITATIONS
  49. XOnly works for HDB uucp.
  50. X.SH AUTHOR
  51. XBill Davidsen, davidsen@crdos1.crd.ge.com
  52. X.SH Copyright
  53. XCopyright (c) 1988,1990 by Bill Davidsen, All rights reserved. This
  54. Xprogram and documentation may be freely distributed and used providing
  55. Xthe copyright notices are kept intact.
  56. SHAR_EOF
  57. chmod 0666 pending.1 || echo "restore of pending.1 fails"
  58. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  59. X# makefile for pending command
  60. X
  61. X# ================> check everything below this line
  62. X
  63. XCFLAGS        = -O
  64. XLFLAGS        = -S
  65. X# remember to use /usr/man/man.LOCAL for SCO
  66. XMANDIR        = /usr/man/man1
  67. X# This is where you install it, like /usr/lbin, /usr/local/bin, 
  68. X# /local, /u/local/bin or /usr/bin as last resort.
  69. XBINDIR        = /u/local/bin
  70. X# your local shar program
  71. XSHAR        = shar
  72. X
  73. X# ================> stop, you've checked enough
  74. X
  75. XBASEFILES    = pending.1 Makefile
  76. XSHARLIST    = $(BASEFILES) pending.c
  77. XSHAROUT        = pending.shar
  78. X
  79. X# magic makerule for SCCS
  80. X.c~.c:
  81. X    get $<
  82. X
  83. X# default
  84. Xdefault:
  85. X    @echo "After you have checked the first few lines of the Makefile"
  86. X    @echo "you can type \"make pending\" or \"make install\"."
  87. X    @echo "You can \"make clean\" after the install is done."
  88. X
  89. Xpending: pending.o
  90. X    $(CC) -o pending $(LFLAGS) pending.o
  91. X
  92. Xinstall: pending pending.1
  93. X    cp pending $(BINDIR)/pending
  94. X    chusr uucp $(BINDIR)/pending
  95. X    chmod 4711 $(BINDIR)/pending
  96. X
  97. Xshar: $(SHAROUT)
  98. X$(SHAROUT): $(SHARLIST)
  99. X    $(SHAR) $(SHARLIST) > $(SHAROUT)
  100. X
  101. Xclean:
  102. X    rm -f pending $(SHAROUT)
  103. X    test -f p.pending.c || rm -f pending.c
  104. X
  105. X# this is for the author!
  106. Xzoo: pending.zoo
  107. XZOOLIST        = $(BASEFILES) s.pending.c
  108. Xpending.zoo: $(ZOOLIST)
  109. X    zoo aunM pending.zoo $?
  110. SHAR_EOF
  111. chmod 0644 Makefile || echo "restore of Makefile fails"
  112. sed 's/^X//' << 'SHAR_EOF' > pending.c &&
  113. X/* list pending HDB requests from a site */
  114. X
  115. X#include <stdio.h>
  116. X
  117. X#define HDBdir    "/usr/spool/uucp"
  118. X#define EOS        '\0'
  119. X
  120. Xstatic char *IDent[] = {
  121. X    "@(#)pending.c v1.2, 10/29/90"
  122. X    "Copyright 1988 by Bill Davidsen, all rights reserved",
  123. X    "May be freely distributed and used providing copyright",
  124. X    "notices are kept intact."
  125. X};
  126. X
  127. Xmain(argc,argv)
  128. Xint argc;
  129. Xchar *argv[];
  130. X{
  131. X    char dirname[1024], filename[32], dataline[132];
  132. X    char xfilename[32], wkfilename[132], *DummY = IDent[0];
  133. X    int slen;                    /* string length */
  134. X    int first1 = 1;                /* flag for 1st time thru */
  135. X    FILE *lsout, *popen(), *xfile, *fopen();
  136. X
  137. X    /* test input */
  138. X    if (argc != 2) {
  139. X        fprintf(stderr, "Format:\n  pending SYSname\n\n");
  140. X        exit(1);
  141. X    }
  142. X
  143. X    sprintf(dirname, "%s/%s", HDBdir, argv[1]);
  144. X    if (chdir(dirname)) {
  145. X        perror("Can't get working dir");
  146. X        exit(1);
  147. X    }
  148. X    
  149. X    lsout = popen("ls X.* 2>&1", "r");
  150. X    if (lsout == NULL) {
  151. X        perror("Can't start ls");
  152. X        exit(1);
  153. X    }
  154. X
  155. X    filename[31] = EOS;
  156. X    /* loop checking files */
  157. X    while (fgets(filename, 31, lsout)) {
  158. X        if (strlen(filename) > 30) {
  159. X            fprintf(stderr, "filename too long\n");
  160. X            exit(1);
  161. X        }
  162. X
  163. X        /* see if there's a file found */
  164. X        sscanf(filename, "%s", xfilename);
  165. X        if (strncmp(xfilename, "X.*", 3) == 0) {
  166. X            fprintf(stderr, "No jobs pending\n");
  167. X            exit(0);
  168. X        }
  169. X
  170. X        /* open the file for reading */
  171. X        xfile = fopen(xfilename, "r");
  172. X        if (xfile == NULL) {
  173. X            perror("Can't open info file");
  174. X            exit(1);
  175. X        }
  176. X
  177. X        /* check for header needed */
  178. X        if (first1) {
  179. X            first1 = 0;
  180. X            printf("\n %-15s %-15s %-15s %s\n",
  181. X                "Job", "User", "Input File", "Task");
  182. X        }
  183. X
  184. X        /* scan the file for various things */
  185. X        printf("%-15s ", xfilename+2);
  186. X        dataline[131] = EOS;
  187. X        while (fgets(dataline, 131, xfile)) {
  188. X            if ((slen = strlen(dataline)) > 130) {
  189. X                /* line too long */
  190. X                while (getc(xfile) != '\n');
  191. X            }
  192. X            dataline[slen-1] = EOS;
  193. X
  194. X            switch (dataline[0]) {
  195. X            case 'U': /* originating user */
  196. X                printf("%-15s ", dataline+2);
  197. X                break;
  198. X            case 'C': /* command */
  199. X                printf("%s\n", dataline+2);
  200. X                break;
  201. X            case 'I': /* input file */
  202. X                printf("%-15s ", dataline+2);
  203. X                break;
  204. X            }
  205. X        }
  206. X
  207. X        /* clean up */
  208. X        fclose(xfile);
  209. X    }
  210. X
  211. X    pclose(lsout);
  212. X    exit(0);
  213. X}
  214. X/* tabs=4 */
  215. SHAR_EOF
  216. chmod 0444 pending.c || echo "restore of pending.c fails"
  217. exit 0
  218.