Skip to main content

man2pdf Convert unix manpage to PDF

#!/bin/bash

#############################################################################
# #
# man2pdf #
# a simple bash script to convert a man page to pdf #
# #
# Copyright (C) 2003-2004 Trond Aasan #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
# If you find this useful in any way, or if you find a bug, #
# feel free to e-mail me. #
# #
# Trond Aasan #
# http://www.aasan.org/ #
# #
#############################################################################

# $Id: man2pdf,v 1.6 2004/01/23 18:35:41 trondaas Exp $

MAN=$(which man)
if [ -z "$MAN" ]; then
echo "man executable not found in path" >&2
exit 1;
fi

GROFF=$(which groff)
if [ -z "$GROFF" ]; then
echo "groff executable not found in path" >&2
exit 1;
fi

GS=$(which gs)
if [ -z "$GS" ]; then
echo "gs executable not found in path" >&2
exit 1;
fi

USAGE="Usage: $0 [options] [outfile]
Options:
-n SECTION man section
-h Print this help message

If no section is specified, use first hit.

If outfile is not specified, write output to .
.pdf in
current directory.
"

unset MANSECT

while getopts 'n:h' opt; do
case $opt in
n )
export MANSECT="$OPTARG"
;;
h )
echo "$USAGE"
exit
;;
\? )
exit 1
;;
* )
echo "Error"
exit 1
;;
esac
done

shift $(($OPTIND - 1))

if [ -z "$1" ]; then
echo "$USAGE"
exit 1
fi

infile=$("$MAN" -w -- "$1") || exit $?

if [ -z "$MANSECT" ]; then
AWK=$(which awk)
if [ -z "$AWK" ]; then
echo "awk executable not found in path. Will not guess man"\
"section" >&2
else
BASENAME=$(which basename)
if [ -z "$BASENAME" ]; then
echo "basename executable not found in path. Will not guess man"\
"section" >&2
else
basename=$("$BASENAME" "$infile")
section=$(echo "$basename" | "$AWK" -F . \
"/$(echo "$1" | tr . '\.')\.([0-9a-zA-Z])(\.gz)?$/{print \$2}")
fi
fi
fi

case "$infile" in
*.gz | *.Z)
CAT=$(which zcat)
;;
*.bz)
CAT=$(which bzcat)
;;
*.bz2)
CAT=$(which bz2cat)
;;
*)
CAT=$(which cat)
;;
esac

if [ -z "$CAT" ]; then
exit 1
fi

if [ -n "$2" ]; then
outfile="$2"
else
if [ -n "$section" ]; then
outfile="$1.$section.pdf"
else
outfile="$1.pdf"
fi
fi

"$CAT" -- "$infile" | "$GROFF" -t -E -Tps -mandoc -ma4 \
| "$GS" -q -sDEVICE=pdfwrite -sOutputFile="$outfile" -dNOPAUSE -dBATCH -sPAPERSIZE='a4' -


[close]

Comments

Popular posts from this blog

NetSurveyor :: 802.11 (WiFi) Network Discovery / Scanner Tool

NetSurveyor :: 802.11 (WiFi) Network Discovery / Scanner Tool http://www.performancewifi.net/performance-wifi/main/NetSurveyor.htm NetSurveyor is an 802.11 (WiFi) network discovery tool and, as such, its goal in life is to gather information about nearby wireless access points in real time and display it in a useful way. Similar in purpose to NetStumbler , it includes many more features. The data is displayed using a variety of different diagnostic views and charts. Data can be recorded for extended periods and played-back at a later date/time. Also, reports can be generated in Adobe PDF format. Applications for NetSurveyor include the following: During the installation of a wireless network, as an aid in verifying the network is properly configured and antennas are positioned at locations to achieve efficient transmission / reception -- that is, for use in verifying WiFi coverage and maximizing beacon signal strength Trouble-shooting an existing network or wireless environm...

Handle Too-Long Command Lines with xargs

Handle Too-Long Command Lines with xargs xargs is one of those UNIX utilities that seems pretty useless when you first hear about it -- but turns into one of the handiest tools you can have. xargs reads a group of arguments from its standard input, then runs a UNIX command with that group of arguments. It keeps reading arguments and running the command until it runs out of arguments. The shell's backquotes do the same kind of thing, but they give all the arguments to the command at once. This can give you a Too many arguments error. Here are a couple of examples: If you want to print most of the files in a large directory, put the output of ls into a file. Edit the file to leave just the filenames you want printed. Give the file to xargs ' standard input: % ls > allfiles.tmp % vi allfiles.tmp % xargs lpr What did that do? With lines like these in allfiles.tmp : % cat allfiles.tmp afile application ... yoyotest zapme xargs ran one or more lpr commands, each wit...

Cisco Command "Auto secure"

Cisco Command "Auto secure" In today's article, I'm going to quickly inform you about the Privileged EXEC command named "auto secure". Network administrators (like you) use the "auto secure" command to secure the management and forwarding planes of a router. Another way of saying it is, CCNAs use this command to secure a router by disabling common IP services which can be exploited by attackers to initiate network attacks. When the command is typed on a router, it takes the user (ccna) through a command line-interface (CLI) semi-interactive session (which is also known as the AutoSecure dialogue). Below is the command's syntax: auto secure [management | forwarding] [no-interact | full] [ntp | login | ssh | firewall | tcp-intercept] As you can see, the command can use several "optional" keywords: management - This (optional) keyword is used to only secure the management plane of a router. forwarding - This (optional) keyword is used to...