scan

Intergalactic Psychic Police Of Uranus jmg at dolphy.UUCP
Mon Oct 7 08:15:20 AEST 1985


*** 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



More information about the Comp.sources.unix mailing list