jmg@dolphy.UUCP (Intergalactic Psychic Police Of Uranus) (10/07/85)
*** amusing & useful program *** What follows is an amusing and useful program to repeatedly execute command(s) and display their output on the screen...overlaying subsequent output on preceding output...thus, you can watch something change over time. The default (expensively) is "ps -af"...so that you can watch the system change. There are all sorts of interesting variations and modifications possible...please send them to me. In releasing this (simple) source please keep my name in it. Finally, we don't have 'nroff' or 'man' macros to make a real man page. #! /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: # README.scan # scan.c # This archive created: Sun Oct 6 18:14:36 1985 # By: Intergalactic Psychic Police Of Uranus (Lesbian Vampires Of Sodom Corp.) export PATH; PATH=/bin:$PATH echo shar: extracting "'README.scan'" '(632 characters)' if test -f 'README.scan' then echo shar: will not over-write existing file "'README.scan'" else cat << \SHAR_EOF > 'README.scan' scan [-s delay] [quoted_command_string] Scan repeats commands over and over displaying only the first screenful via curses. Thus, one can view the changes. The default command is "ps -af" and the default delay between repeats of commands in 4 seconds. Commands must be quoted, for example scan "date;ps -fu root & df" will run 'date', then the 'ps' in the background and df", wait for the 'df', display as much as will fit on the screen of the entire output, and repeat. Stop it by interrupting. A delay of zero seconds IS possible. Author: Jeffrey Greenberg (allegra!phri!dolphy!jmg), after Rusty Wright (sdcarl!rusty). SHAR_EOF fi # end of overwriting check echo shar: extracting "'scan.c'" '(1613 characters)' 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... */ #include <stdio.h> #include <curses.h> 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(); cbreak(); 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(); nocbreak(); 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 # End of shell archive exit 0
mike@peregrine.UUCP (Mike Wexler) (10/18/85)
> *** 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 <stdio.h> #include <curses.h> 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
patrick@sftig.UUCP (P.Arnoux) (10/20/85)
Posted in error, Please ignore.