Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site peregrine.UUCP Path: utzoo!linus!decvax!tektronix!hplabs!oliveb!felix!ccicpg!peregrine!mike From: mike@peregrine.UUCP (Mike Wexler) Newsgroups: net.sources Subject: Re: scan Message-ID: <205@peregrine.UUCP> Date: Thu, 17-Oct-85 20:44:21 EDT Article-I.D.: peregrin.205 Posted: Thu Oct 17 20:44:21 1985 Date-Received: Mon, 21-Oct-85 06:45:56 EDT References: <11@dolphy.UUCP> Distribution: net Organization: Peregrine Systems, Irvine, Ca Lines: 246 > *** amusing & useful program *** > > What follows is an amusing and useful program to repeatedly execute > command(s) and display their output on the screen...overlaying I have modified this program to work with termcap. Also I have added a makefile and documentation in man form. I personally find documentation in man format much more useful than nroffed output because I can use it with the man program. I think that most people have it. If you need a formatted version please send me mail at trwrb!felix!peregrine!mike. Mike(always a dreamer) Wexler 15530 Rockfield, Building C Irvine, Ca 92718 (714)855-3923 (trwrb|scgvaxd)!felix!peregrine!mike -------------------- 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: # scan.l # scan.c # makefile # This archive created: Thu Oct 17 17:35:02 1985 export PATH; PATH=/bin:$PATH if test -f 'scan.l' then echo shar: will not over-write existing file "'scan.l'" else cat << \SHAR_EOF > 'scan.l' .TH SCAN l "17 October, 1985" .SH NAME scan \- repeat a command .SH SYNOPSIS scan [-s delay] [quoted_command_string] .SH DESCRIPTION .PP .I Scan repeats commands over and over displaying only the first screenful via .IR curses (3X). Thus, one can view the changes. .PP The default command is "ps -af" and the default delay between repeats of commands in 4 seconds. Commands must be quoted. .PP Stop it by interrupting. .SH EXAMPLES .RB scan "date;ps -fu root & df" .PP Will run .IR date (1), then the .IR ps (1) in the background and .IR df (1), wait for the .IR df (1), display as much as will fit on the screen of the entire output, and repeat. .SH OPTIONS .IP "-s delay" Set the delay between refreshing the screen. A delay of zero seconds IS possible. .SH AUTHORS .PP Jeffrey Greenberg (allegra!phri!dolphy!jmg) .PP Rusty Wright (sdcarl!rusty). .SH BUGS .PP A delay of zero will keep your cpu very busy. SHAR_EOF fi # end of overwriting check if test -f 'scan.c' then echo shar: will not over-write existing file "'scan.c'" else cat << \SHAR_EOF > 'scan.c' /* * scan: 'real time' screen display - by jeffrey greenberg * Copyright 1984 Jeffrey Greenberg * ALL RIGHTS RESERVED * Source given for non-profit use only! (Please give me credit & * mail me changes!) * * compile: cc scan.c -lcurses * Should run on system 5... * * Oct 17, 1985 by Michael C Wexler(trwrb!felix!peregrine!mike) * Added V7 flag to allow running under Version 7 derivatives */ #include #include int seconds; main(argc, argv) int argc; char *argv[]; { FILE *str; int intrp(); int c; int minarg; char *execstr, *getopts(); char *copyright; copyright = "Jeffrey Greenberg 1984/85 - ALL RIGHTS RESERVED"; execstr = getopts(argc,argv); initscr(); signal(2,intrp); nonl(); #ifndef V7 /* modified Oct 17, 1985 by MCW */ cbreak(); #else crmode(); #endif noecho(); clear(); refresh(); loop: if( (str = popen( execstr, "r")) == NULL ) panic( execstr ); move(0,0); while( (c=fgetc( str )) != EOF ) addch(c); clrtobot(); refresh(); pclose( str ); if(seconds ) sleep( seconds ); goto loop; } panic( str ) char *str; { perror( str ); cleanup(); exit(1); } intrp() { cleanup(); exit(0); } cleanup() { echo(); nl(); #ifndef V7 /* modified by MCW on Oct 17, 1985 */ nocbreak(); #endif endwin(); } char * getopts( argc, argv ) int argc; char **argv; { int option, badopt = 0; extern int optind; extern char *optarg; static char exec_default[] = {"ps -af"}; char *execstr; seconds = 4; /* default sleep time in seconds */ while( (option=getopt(argc,argv,"s:")) != EOF ) if( option == 's' ) { if( (seconds = atoi(optarg)) < 0) ++badopt; } else { ++badopt; } if( badopt ) { fprintf(stderr,"Usage: scan [-s seconds] [quoted_command_string]\n"); exit(1); } if( (argc - 1) < optind ) execstr = exec_default; else execstr = argv[optind]; return execstr; } SHAR_EOF fi # end of overwriting check if test -f 'makefile' then echo shar: will not over-write existing file "'makefile'" else cat << \SHAR_EOF > 'makefile' # Installation parameters # Directory where local binaries are put BIN=/usr/local/bin # Directory where manual pages are put MAN=/usr/man/manl # load termcap library(termlib on System V) TERMCAP=-ltermcap # Operating system: # V7 - version 7 and 4.? BSD # SYS - for System III & System V OPSYS=V7 # Don't change past here CFLAGS=-O -D$(OPSYS) $(OPT) LFLAGS=-s LOADLIBES=-lcurses $(TERMCAP) LIB=scan.o OUT=scan.bin ALL: $(OUT) $(OUT): $(LIB) .SUFFIXES: .SUFFIXES: .c .o .bin .c.o: $(CC) $(CFLAGS) -c $< .o.bin: $(CC) -o $@ $(LFLAGS) $< $(LOADLIBES) clean: rm *.o install: ln scan.l $(MAN) ln scan.bin $(BIN)/scan SHAR_EOF fi # end of overwriting check # End of shell archive exit 0 -- Mike(always a dreamer) Wexler 15530 Rockfield, Building C Irvine, Ca 92718 (714)855-3923 (trwrb|scgvaxd)!felix!peregrine!mike