allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (04/09/89)
Posting-number: Volume 6, Issue 84 Submitted-by: "John D. DiMarco" <jdd@db.toronto.edu> Archive-name: lowlav Description: lowlav: given a list of hosts, return the name of the host with the lowest load average. It's very simple, needs no makefile or readme. A man-page is included. It may be BSD - specific (does SYSV use /usr/spool/rwho/whod.* ?) #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # If this archive is complete, you will see the following message at the end: # "End of shell archive." # # Contents: # lowlav.1 lowlav.c # # Wrapped by jdd@db.toronto.edu on Fri Mar 31 20:04:43 1989 # PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f lowlav.1 -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"lowlav.1\" else echo shar: Extracting \"lowlav.1\" \(600 characters\) sed "s/^X//" >lowlav.1 <<'END_OF_lowlav.1' X.TH LOWLAV 1V "31 March 1989" X.SH NAME Xlowlav \- print host with lowest load average X.SH SYNOPSIS X.B lowlav X[ -v ] [ -f hostfile ] X.SH DESCRIPTION X.I lowlav Xreads a list of hosts from the standard input, returns the host with the lowest Xload average. X.nf X.br X.SH OPTIONS X.IP \fB\-f\ \fIhostfile\fP XRead hosts from file "hostfile" instead of from the standard input. X.IP \fB\-v \fP XVerbose. Print an error message for every host not in /usr/spool/rwho. X.SH AUTHOR XJohn DiMarco, University of Toronto, 1989 X.SH FILES X/usr/spool/rwho/whod.* Data Files X.SH SEE ALSO Xruptime(1C), rwho(1C), rwhod(8C) END_OF_lowlav.1 if test 600 -ne `wc -c <lowlav.1`; then echo shar: \"lowlav.1\" unpacked with wrong size! fi # end of overwriting check fi if test -f lowlav.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"lowlav.c\" else echo shar: Extracting \"lowlav.c\" \(2067 characters\) sed "s/^X//" >lowlav.c <<'END_OF_lowlav.c' X/* XGiven a list of machine names, return the name of the machine in that list Xwith the lowest load average in /usr/spool/rwho. X XWritten by John DiMarco, March 1989 at the University of Toronto XBased on a program 'asun' by Jonathon Haruni. X X */ X X#include <stdio.h> X#include <string.h> X X#define STREQ(a,b)(strcmp((a),(b)) == 0) X#define TRUE 1 X#define FALSE 0 X X#define TOOBIGLOAD 30000 X Xextern char *getenv(); Xextern char *optarg; Xextern int opterr; X Xstruct partofrwhodfile { X char fill[4]; X int garbage[2]; X char hostname[32]; X int loadav; X}; X X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X FILE *fp, *input; X int c, verbose, bestload = TOOBIGLOAD; X char besthost[32]; X char thishost[80]; X char filename[120]; X struct partofrwhodfile entry; X X *besthost = '\0'; X X verbose = FALSE; X input = stdin; X X while((c = getopt(argc, argv, "vf:")) != EOF){ X switch(c){ X case 'v': X /* Verbose mode: print out error messages for */ X /* hostnames which don't appear in /usr/spool/rwho */ X verbose = TRUE; X break; X case 'f': X /* Take input from a file rather than stdin */ X input = fopen(optarg, "r"); X if(NULL==input){ X (void)fprintf(stderr, X "%s: Can't open file %s \n", X argv[0], optarg); X (void)exit(1); X } X break; X case '?': X (void)fprintf(stderr, "Usage: %s [-v] [-f filename]\n", X argv[0]); X (void)exit(1); X break; X } X X } X X while(!feof(input)){ X (void)fscanf(input, "%80s ", thishost); X (void)sprintf(filename,"/usr/spool/rwho/whod.%s", X thishost); X if((fp = fopen(filename,"r")) != NULL) { X (void)fread(&entry,sizeof(struct partofrwhodfile), X 1,fp); X (void)fclose(fp); X if(entry.loadav < bestload) { X (void)strcpy(besthost,thishost); X bestload = entry.loadav; X } X } else { X if(verbose){ X fprintf(stderr, "%s: %s not found\n", X argv[0], filename); X } X } X } X if(TOOBIGLOAD == bestload){ X (void)fprintf(stderr, "%s: No data for specified hosts\n", X argv[0]); X (void)exit(1); X } X (void)printf("%s\n",besthost); X if(input!=stdin) X (void)fclose(input); X} END_OF_lowlav.c if test 2067 -ne `wc -c <lowlav.c`; then echo shar: \"lowlav.c\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of shell archive. exit 0 ---- John John DiMarco * We will live in the light * jdd%db.toronto.edu@relay.cs.net jdd@db.toronto.edu jdd@db.utoronto.ca jdd@db.toronto.cdn {uunet!utai,watmath!utai,decvax!utcsri,decwrl!utcsri}!db!jdd jdd@utcsri.UUCP