Shell Logging

Maarten Litmaath maart at cs.vu.nl
Sat Oct 21 01:36:40 AEST 1989


selig at udcps3.cps.udayton.edu (Paul D. Selig) writes:
\I need to have a way that will take a shell script that is written by a
\student and run that script, while at the same time writing all input
\(either from the keyboard or a file), output, and error output to a "log"
\file, while at the same time accepting input from the keyboard and writing
\the output to the screen.  [...]

/usr/ucb/script would do what you want.
If you only want to log error messages, you can use the following script.
----------8<----------8<----------8<----------8<----------8<----------
#!/bin/sh
# @(#)log 1.1 89/06/10 Maarten Litmaath
# log - save error messages in a logfile, duplicate them on stderr

test $# -lt 2 && {
	echo "Usage: `basename $0` <error logfile> <command>" >&2
	exit 1
}

ERRLOG=$1
shift

exec 3>&1
"$@" 2>&1 >&3 3>&- | tee -a "$ERRLOG" >&2
----------8<----------8<----------8<----------8<----------8<----------
-- 
A symbolic link is a POINTER to a file, | Maarten Litmaath @ VU Amsterdam:
 a hard link is the file system's GOTO. | maart at cs.vu.nl, mcsun!botter!maart



More information about the Comp.unix.questions mailing list