|
This pair of scripts was developed for the
purpose of printing system files in a readable
format. In order to keep documentation of
systems up to date, I started printing out
various config files. However a straight
text file sent to the printer will often
have lines truncated if they extend past
the edge of the page, and opening each file
in an editor and formatting them proved very
time consuming. Therefore I prepared a list
of configuration files on each machine that
I wanted to print, and then put together
a small script to send them to the default
printer. This script requires mpage to be
installed, and of course a printer set up.
See the mpage manual for a description of
the flags being used.
This example has the config file in root's
directory (and runs as root) because some
of the files I want to print are readable
only by root. More security conscious individuals
may want to run them as a different user.
The config file is simply a list of files
that are to be printed, one file to a line
as so:
/etc/lilo.conf
/etc/hosts.allow
/etc/hosts.deny
/etc/hosts.lpd
These scripts were developed on Linux, and
also run on OpenBSD by substituting /bin/sh
for /bin/bash.
#docprint
#26 July 2003 James Zuelow
#!/bin/bash
DTE=`date +"%d %B, %Y"`
for FL in `cat /root/doclist`; do
mpage -1 -bletter -Plp -m50lr -X"`hostname`:
$FL $DTE" -W132 -f $FL;
done
exit 0
There are occasions where I only need
to
print a single file instead of the
whole
batch. A modified script serves this
purpose:
#printdoc
#26 July 2003 James Zuelow
#!/bin/bash
main() {
DTE=`date +"%d %B, %Y"`
mpage -1 -bletter -Plp -m50lr -X"`hostname`:
$1 $DTE" -W132 -f $1
echo "Printing $1"
exit 0
}
error() {
echo ""
echo ""
echo "Usage: printdoc [file]"
if [ $EC -eq 1 ]; then
echo " Use printdoc to print a
single
file."
echo " Use docprint to print preconfigured
list.";
elif [ $EC -eq 2 ]; then
echo " File not found. Check your
path.";
fi
echo ""
echo ""
exit 0
}
if [ $# -ne 1 ]; then EC=1; error $EC;
fi
if [ -e $1 ]; then main $1; fi
EC=2
error $EC
exit 0
|
|