Home About BC DR HA Support Training Download
You are here: Home/ Downloads/ Scripts/ Korn/ Please Login or Register

-
Current Location
-

js
  Downloads
    Scripts
      Korn



-
 Mt Xia Inc.
-
BOOK:Advanced Shell Scripting



 Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com
-
 Train By Tweet
Training courses Tweet By Tweet
Various Subjects and Products
TrainByTweet.com


AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com
-

digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com

Script Source Code for "autocontent"

This document contains the source code for the Automated Documentation Generator script "autocontent". This document was automatically generated using the "autocontent" script.

To view the Automatically Generated Documentation from the "autocontent" Script, Click Here.




#!/usr/bin/ksh93
################################################################
function usagemsg_autocontent {
  print -- "
Program: autocontent

This utility parses a list of scripts, extracts the comments from within
each script in the list, and generates HTML formatted documentation from
the extracted comments and source code.

This utility reads a data file containing the location of local or
remote script files, and the location for the resulting documentation.
The data file also contains SSH communication information for both the
source and destination locations.

Usage: ${1##*/} [-vV?] {-d|-h|-l|-f datafile} [-o] [-c|-u] [-p sshport]
                [-H] [-T TitleFile] [-F FooterFile]

  Where:
    -? = Display usage and help message
    -v = Verbose Mode
    -V = Very Verbose Mode
    -d = Use ./.autocontent.dat as the data file 
    -h = Use ~/.autocontent.dat as the data file from your home directory (Default)
    -l = Use /usr/local/AutoContent/AutoContent.dat as the data file
    -f datafile = Specify the AutoContent Data File
    -o = Send all HTML output to STDOUT
    -c = Generate code document only
    -u = Generate usage document only
    -p sshport = SSH Port number to use for file transfer (default:22)

    -H = Generate Standalone HTML files instead of SSI files (Default: SSI)
         Automatically includes ~/.autocontent_header.html and 
         ~/.autocontent_footer.html if they exist.

    -T titleFile  = Header file inserted at the Start of HTML Standalone files.
                    (Default: ~/.autocontent_header.html)
    -F footerFile = Footer file inserted at the End of HTML Standalone files.
                    (Default: ~/.autocontent_footer.html)

Author: Dana French (dfrench@mtxia.com) Copyright 2007-2015, All Rights Reserved

\"AutoContent\" enabled
"
  return 0
}
################################################################
#### 
#### Description:
#### 
#### This utility parses a list of scripts, extracts the comments from within
#### the scripts, and builds HTML Server Side Include (SSI) files from the
#### extracted comments and source code. Optionally this utility can also
#### generate standalone HTML files, but the normal usage is to generate HTML
#### SSI files. The HTML SSI file is saved in a location designated by the
#### user under a file name comprised of the original file name suffix up to
#### the first dot ".", followed by ".content.shtml". The "shtml" extention
#### is used for server-side include (SSI) files.
#### 
#### Operation of "AutoContent" is controlled by a data file that contains
#### information about the files to be processed. Each line of the data file
#### represents a record of information and is processed in sequence. Each
#### line of data is formatted into a "source" and "destination" portion. The
#### source portion designates a file to be processed by  "AutoContent" and
#### the machine on which it resides. The destination portion of the data
#### line designates a machine and directory location to place the results of
#### the processing.
#### 
#### The "AutoContent" script will generate documentation for shell scripts
#### that exist on a local or remote server, and push the generated HTML
#### documentation to a local or remote web server. Each line of the data
#### file can be configured independently of every other line in the file.
#### This means that each line can refer to a shell script on a different
#### remote system, and can transfer the generated documentation to a
#### different web server for each shell script. Or each shell script can
#### exist on the same local or remote host, and transfer the generated
#### documentation to the same local or remote web server. How and where is
#### up to the user.
#### 
#### The data file consists of a series of lines, one record per line. A
#### record consists of several fields specifying a SSH ports, Usernames,
#### Hostnames, and full path file names, and an optional field whose
#### contents are variable. Each record line is divided into source and
#### destination portions which specify where to retrieve the script files,
#### and where to place the generated documentation files.
#### 
#### Example data file records:
#### 
#### # SRCSSHPORT:srcuser@srcmachine:/source/file/location.sh:helpFlag|DESTSSHPORT:destuser@destmachine:/destination/directory<BR/>
#### 22:username@xyzmach:/usr/local/bin/script01.ksh:-?|22:apache@webserver:/www/httpd/html/scripts<BR/>
#### 22:username@xyzmach:/usr/local/bin/another02.sh:-?|22:apache@webserver:/www/httpd/html/scripts<BR/>
#### 22:username@xyzmach:/home/username/scripts/drscript.sh:-?|2022:wikisysop@wikiserver:/var/www/html/holding<BR/>
#### 
#### In the above examples, the optional field following the full path source
#### file name contains the characters "-?". This causes "AutoContent" to
#### execute this script with a "-?" option on the command line expecting to
#### receive a usage message. The usage message is captured and added to the
#### documentation.
#### 
#### In the Data File, blank lines or lines beginning with a hash mark "#" are
#### ignored.
#### 
#### Each line in the data file is divided into two parts separated by a pipe "|" symbol.
#### The first part of the data line is the source file information, the second part is the
#### destination location for the documentation.
#### 
#### The source portion of the data line is divided into the following
#### components, separated by a colon ":" character
#### 
####  o SSH Port Number, followed by a colon ":" separator.
#### 
####  o Username on the remote machine for SSH access to retrieve source
####     script file, followed by an "@" character.
#### 
####  o Remote hostname for SSH access to retrieve source script file,
####     followed by a colon ":" separator.
#### 
####  o Full path file name to the remote script file to retrieve for
####     documentation, optionally followed by a colon ":" separator or a pipe
####     "|" symbol depending upon if a usage message should be retrieved from
####     the script for the documentation.
#### 
####  o If a usage message can be retrieved from the remote script file
####     using a "-? command line argument, then include a ":-?" after the full
####     path file name to the remote script. This will cause the script to be
####     executed with the "-?" command line argument to generate and capture the
####     usage message.
#### 
#### The destination portion of the data line is divided into the following
#### components, separated by a colon ":" character
#### 
####  o SSH Port Number on the remote web server machine, followed by a
####     colon ":" separator.
#### 
####  o Username on the remote web server machine for SSH access to send
####     documentation files, followed by an "@" character.
#### 
####  o Remote hostname of the web server for SSH access to send
####     documentation files, followed by a colon ":" separator.
#### 
####  o Full path directory name to the remote web server to send generated
####     documentation.
#### 
#### Assumptions:
#### 
#### It is assumed that any file defined in the data file with  the "-?"
#### optional field, is an executable file, recognizes the "-?" option and
#### generates a usage message if the script is executed with that option. 
#### Each file defined using  the "-?" optional field WILL BE EXECUTED with
#### the "-?" option to generate the usage message.  If the script does not
#### recognize the "-?" option, THE SCRIPT WILL EXECUTE as though no command
#### line arguments were provided and perform whatever tasks it does under
#### that condition.  Be sure that any file referenced by "autocontent" using
#### the "-?" optional field, recognizes  the "-?" option.
#### 
#### Additional documentation may be generated if the comments within the
#### script conform to the "autocontent" technique of imbedding comments in
#### scripts.
#### 
#### Dependencies:
#### 
#### The "autocontent" script is a Korn Shell 93 script and must be executed
#### using a Korn Shell 93 compliant script interpreter.
#### 
#### Products:
#### 
#### For each specified script, the "autocontent" script generates either an
#### SSI HTML file or a stanalone HTML file. The HTML generated documentation
#### contains the usage message and any additional comments extracted from
#### the script.  Also produced is a separate HTML SSI or standalone file
#### that contains the script itself enclosed in HTML tags to preserve
#### formatting.
#### 
#### Configured Usage:
#### 
#### This script requires no arguments and can be run from the command line,
#### scheduled, or executed from within another script. This script performs
#### file transfers between the system running this scripts and any number of
#### remote systems and web servers. How the files generated by this script
#### are utilized is beyond the scope of this script.
#### 
#### Details:
#### 
################################################################
function autocontent
{
    export DD_TMP="${DD_TMP:-/tmp}"

    typeset VERSION="20150403.01"
    typeset TRUE=1
    typeset FALSE=0
    typeset VERBOSE="${FALSE}"
    typeset VERYVERB="${FALSE}"

    typeset AUTOCONTENT=~/.autocontent.dat
    typeset HEADFILE=~/.autocontent_header.html
    typeset FOOTFILE=~/.autocontent_footer.html
    typeset CMD_SH="ssh"
    typeset CMD_CP="scp"
    typeset CMD_RM="rm -f"
    typeset CMD_SHELL="/usr/bin/ksh93"
    typeset CODEDOC="${TRUE}"
    typeset HNAME="$( uname -n )"
    typeset SSHPORT="22"
    typeset SSHUSER="apache"
    typeset STDOUT="${FALSE}"
    typeset SUFFIX="content.shtml"
    typeset TMPFILE="/tmp/tmp${$}.tmp"
    typeset USAGEDOC="${TRUE}"
    typeset HTMLOUT="${FALSE}"

    typeset DATAFILE
    typeset CMD
    typeset FILENAME
    typeset LINE
    typeset OUTFILE
    typeset SRC
    typeset SRCPORT
    typeset SRCUSER
    typeset SRCMACH
    typeset SRCFILE
    typeset SRCFLAG
    typeset DEST
    typeset DESTPORT
    typeset DESTUSER
    typeset DESTMACH
    typeset DESTDIR
    typeset DESTNAME
    typeset MSG

    while getopts ":vVdhlf:ocup#HT:F:" OPTION
    do
        case "${OPTION}" in
            'd') AUTOCONTENT="./.autocontent.dat" ;;
            'h') AUTOCONTENT=~/.autocontent.dat ;;
            'l') AUTOCONTENT="/usr/local/AutoContent/AutoContent.dat";;
            'f') AUTOCONTENT="${OPTARG}";;
            'o') STDOUT="${TRUE}";;

            'c') CODEDOC="${TRUE}"
                 USAGEDOC="${FALSE}";;

            'u') USAGEDOC="${TRUE}"
                 CODEDOC="${FALSE}";;

            'p') SSHPORT="${OPTARG}";;

            'H') HTMLOUT="${TRUE}"
                 SUFFIX="html";;

            'T') HEADFILE="${OPTARG}"
                 HTMLOUT="${TRUE}"
                 SUFFIX="html";;

            'F') FOOTFILE="${OPTARG}"
                 HTMLOUT="${TRUE}"
                 SUFFIX="html";;

            'v') VERBOSE="${TRUE}";;
            'V') VERYVERB="${TRUE}";;
            '?') usagemsg_autocontent "${0}" && exit 1 ;;
            ':') usagemsg_autocontent "${0}" && exit 1 ;;
        esac
    done
     
    shift $(( ${OPTIND} - 1 ))
     
    (( VERYVERB == TRUE )) && set -x
    (( VERBOSE  == TRUE )) && print -u 2 "# ${0} Version: ${VERSION}"

    SRCPORT="${SSHPORT}"
    DESTPORT="${SSHPORT}"

################################################################

    trap "usagemsg_autocontent ${0}" EXIT

    DATAFILE="${AUTOCONTENT:?ERROR: run \"${0} -?\" for help and usage}"

    if [[ -f "${AUTOCONTENT}" ]]
    then
        (( VERBOSE == TRUE )) && print -u 2 "# Specified data file found"
        (( VERBOSE == TRUE )) && print -u 2 "#     ${AUTOCONTENT}"
    else
        print -u 2 "# ERROR: AutoContent data file does not exist"
        print -u 2 "#     ${AUTOCONTENT}"
        exit 2
    fi

    trap "-" EXIT

################################################################
#### 
#### Read data line records:
#### 
#### This script is primarily used to automatically generate documentation
#### content in association with the Disaster Recovery scripts.  However
#### this is an arbitrary association, this script is generic and can
#### be used with any scripts which conform to the rules by which
#### "AutoContent" operates.
#### 
#### Data lines are read from a user designated file that contains
#### information that controls the operation of "AutoContent".
#### Each line of data should be formatted into a "source" and 
#### "destination" portion.  The source portion designates a file
#### to be processed by "AutoContent" and the machine on which it
#### resides.  The destination portion of the data line designates
#### a machine and directory location to place the results of the
#### processing.
#### 
#### Each line in the data file should be formatted as follows:
#### 
#### {SshPortNumber}:{Username}@{source machine name}:{Full Path File Name}[:-?]  \
#### {pipe symbol "|"}  \
#### {SshPortNumber}:{Username}@{destination machine name}:{Full Path Directory Name}
#### 
#### If the option flag "-?" is used at the end of a source
#### file name, the file will be treated as as script and
#### executed using the option flag as an argument.  This
#### assumes the option flag will cause the script to 
#### generate a usage message which will be captured and 
#### included in the generated documentation.
#### 
#### If used, the optional flag must be separated from the 
#### source file name using a colon (:).
#### 
################################################################

    (( VERBOSE == TRUE )) && print -u 2 "# Building scripts overview document"

    while IFS="" read -r -- LINE
    do
        [[ "_${LINE}" == "_" ]] && continue
        [[ "_${LINE}" == _#* ]] && continue

        print -u 2 "# ${LINE%%+([[:blank:]]|,|\|)*}"

        if [[ "_${LINE}" == _*+([[:blank:]]|,|\|)* ]]
        then
            (( VERBOSE == TRUE )) && print -u 2 "# Data line properly divided into SRC and DEST."
        else
            print -u 2 "# "
            print -u 2 "# ERROR: Data line improperly formatted."
            print -u 2 "# ERROR: Unable to determine SRC and DEST areas."
            print -u 2 "# ERROR: ${LINE}"
            print -u 2 "# "
            continue
        fi

################################################################
#### 
#### Parse the "source" portion of the data line record:
#### 
#### The source portion of the data line is extracted from the data line by
#### deleting the largest matching pattern from the end of the line that
#### matches anything up to the first pipe symbol in the line. The result
#### contains the SSH port Number, the SSH User name, source machine name,
#### the source file name, and possibly an option flag. The format of the
#### result should have a colon (:) between the SSH Port Number and the User
#### name, also between source machine name and the source file name, and if
#### present, the help option flag.
#### 
#### If the result is formatted correctly, it is separated in to its
#### components. If the help option flag is present, it is saved in a
#### variable named "SRCFLAG".
#### 
################################################################

        SRCFLAG=""
        SRC="${LINE%%+([[:blank:]]|,|\|)*}"

        if [[ "_${SRC}"     ==  _*:*@*:* ]] &&
           [[ "_${SRC##*:}" != '_'       ]] &&
           [[ "_${SRC%%:*}" != '_'       ]] &&
           [[ "_${SRC#*:}"  !=  _-?*     ]]
        then
            SRCPORT="${SRC%%:*}"     # delete everything up to the first :
            (( VERBOSE == TRUE )) && print -u 2 "# SRCPORT...: ${SRCPORT}"

            SRCUSER="${SRC%%@*}"     # delete everything after @
            SRCUSER="${SRCUSER##*:}" # delete the leading SSH Port
            (( VERBOSE == TRUE )) && print -u 2 "# SRCUSER...: ${SRCUSER}"

            SRCMACH="${SRC##*@}"     # delete from beginning of line up to @
            SRCMACH="${SRCMACH%%:*}" # delete from end of line up to first :
            (( VERBOSE == TRUE )) && print -u 2 "# SRCMACH...: ${SRCMACH}"

            SRCFILE="${SRC##*@}"     # delete from beginning of line up to @
            SRCFILE="${SRCFILE#*:}"  # delete from beginning of line up to first :

            SRCFLAG=""

            if [[ "_${SRCFILE##*:}" == _-?* ]]
            then
                (( VERBOSE == TRUE )) && MSG="# SRC portion of data line properly divided into Port, User, Host, File, and Flag."
                SRCFLAG="${SRCFILE##*:}"
                SRCFILE="${SRCFILE%%:*}"
            else
                (( VERBOSE == TRUE )) && MSG="# SRC portion of data line properly divided into Port, User, Host, and File."
            fi

            (( VERBOSE == TRUE )) && print -u 2 "# SRCFILE...: ${SRCFILE}"
            (( VERBOSE == TRUE )) && print -u 2 "# SRCFLAG...: ${SRCFLAG}"
            (( VERBOSE == TRUE )) && print -u 2 "${MSG}"

        else
            print -u 2 "# "
            print -u 2 "# ERROR: SRC portion of data line improperly formatted."
            print -u 2 "# ERROR: Unable to determine MACH and FILE areas."
            print -u 2 "# ERROR: ${SRC}"
            print -u 2 "# "
            continue
        fi

################################################################
#### 
#### Parse the "destination" portion of the data line record:
#### 
#### The destination portion of the data line is extracted from the data line
#### by deleting the largest matching pattern from the beginning of the line
#### that matches anything up to the last pipe symbol in the line. The 
#### result contains the SSH Port Number for the destination machine,
#### Username, destination machine name and the destination directory. The
#### format of the result should have a colon (:) between the SSH Port Number
#### and Username, and between then destination machine name and the 
#### destination directory.
#### 
#### There should also be an "@" sign between the Username and the
#### destination machine name.
#### 
#### If the result is formatted correctly, it is separated in to its
#### components. 
#### 
################################################################

        DEST="${LINE##*+([[:blank:]]|,|\|)}"

        if [[ "_${DEST}"     ==  _*:*@*:* ]] &&
           [[ "_${DEST##*:}" != '_'       ]] &&
           [[ "_${DEST%:*}"  != '_'       ]]
        then

            DESTPORT="${DEST%%:*}"     # delete everything up to the first :
            (( VERBOSE == TRUE )) && print -u 2 "# DESTPORT...: ${DESTPORT}"

            DESTUSER="${DEST%%@*}"     # delete everything afer @
            DESTUSER="${DESTUSER##*:}" # delete the leading SSH Port
            (( VERBOSE == TRUE )) && print -u 2 "# DESTUSER...: ${DESTUSER}"

            DESTMACH="${DEST##*@}"     # delete from beginning of line up to @
            DESTMACH="${DESTMACH%%:*}" # delete from end of line up to first :
            (( VERBOSE == TRUE )) && print -u 2 "# DESTMACH...: ${DESTMACH}"

            DESTDIR="${DEST##*@}"      # delete from beginning of line up to @
            DESTDIR="${DESTDIR#*:}"    # delete from beginning of line up to first :

            (( VERBOSE == TRUE )) && print -u 2 "# DESTDIR...: ${DESTDIR}"

            (( VERBOSE == TRUE )) && print -u 2 "# DEST portion of data line properly divided into Port, User, Host, and Dir."

        else
            print -u 2 "# "
            print -u 2 "# ERROR: DEST portion of data line improperly formatted."
            print -u 2 "# ERROR: Unable to determine MACH and DIR areas."
            print -u 2 "# ERROR: ${DEST}"
            print -u 2 "# "
            continue
        fi

################################################################
#### 
#### Define the Command to Retrieve the Script File:
#### 
#### Define the command to use to copy the source file from its original
#### location into a temporary file. Assume the source file exists on a
#### remote machine and define the copy command as a remote copy, followed by
#### the SSH Port number option and value, followed by the Username and "@"
#### signe, followed by the source machine name. Then test to see if the
#### source machine name is the same as the local machine name or defined as 
#### "localhost". If so, reset the copy command to be a simple copy followed
#### by a space.
#### 
#### After defining the copy command, perform the copy.
#### 
################################################################

        CMD="${CMD_SH} -p ${SRCPORT} ${SRCUSER}@${SRCMACH}"

        [[ "_${SRCMACH}" == _*${HNAME}* ]] && CMD="eval "
        [[ "_${SRCMACH}" == _localhost  ]] && CMD="eval "

        (( VERBOSE == TRUE )) && print -u 2 "# ${CMD_RM} \"${TMPFILE}\""
        ${CMD_RM} "${TMPFILE}"

        (( VERBOSE == TRUE )) && print -u 2 "# ${CMD} \"cat ${SRCFILE}\" > \"${TMPFILE}\""
        ${CMD} "cat ${SRCFILE}" > "${TMPFILE}"

        FILENAME="${SRCFILE##*/}"

################################################################
#### 
#### Create the Usage Document:
#### 
#### For each script, an HTML Server Side Include (SSI) file is created to
#### contain the usage message and any additional "autocontent" compliant 
#### comments that can be extracted from the script. This file is named using
#### the file name suffix of the original script up to but not including the
#### first dot ".", followed by "doc.content.shtml".
#### 
#### The ".shtml" is used so the document may additionally use server-side
#### includes.
#### 
################################################################

        if (( USAGEDOC == TRUE ))
        then

            OUTFILE="${DD_TMP}/${FILENAME%%.*}doc.${SUFFIX}"
            (( STDOUT == TRUE )) && OUTFILE='&1'

            (( VERBOSE == TRUE )) && print -u 2 "# Building ${FILENAME} usage document: ${OUTFILE}"

            eval "exec 3>${OUTFILE}"

            if (( HTMLOUT == TRUE ))
            then
                if [[ -f "${HEADFILE}" ]]
                then
                    sed -e "s/SCRIPTNAME/${FILENAME%%.*} Shell Script Usage Document/g" "${HEADFILE}" >&3
                else
                    print -u 3 "<HTML><BODY>"
                fi
                print -u 3 "\n<!-- ################################################################ -->\n"
            fi

            print -u 3 "<!-- Begin \"${FILENAME}doc.${SUFFIX}\" -->"
      
################################################################
#### 
#### Generate the Usage Message if applicable:
#### 
#### Each Script is executed with the "-?" option to generate the
#### usage message associated with the script.  This usage message
#### is saved in the documentation for the script.
#### 
#### Any "<" or ">" symbols generated by the usage message or extracted
#### from the script in the additional comments, are converted to
#### HTML recognizable codes that will be interpreted by the web
#### browser when the page is displayed.
#### 
################################################################
      
            if [[ "_${SRCFLAG}" != "_" ]]
            then
                (( VERBOSE == TRUE )) && print -u 2 "# Executing script to generate usage message"
                print -u 3 "<P><BLOCKQUOTE><STRONG><PRE><CODE>"
                chmod 755 "${TMPFILE}"
                ${CMD_SHELL} "${TMPFILE}" -? 2>&1 |
                  sed -e "s/</\&lt;/g;s/>/\&gt;/g;s|${TMPFILE##*/}|${SRCFILE##*/}|g" |
                  grep -v "ERROR" >&3
      
                print -u 3 "</CODE></PRE></STRONG></BLOCKQUOTE></P>"
            fi

            (( VERBOSE == TRUE )) && print -u 2 "# Generating additional documentation for \"${FILENAME}\""
            print -u 3 "<P><HR></P>"
      
################################################################
#### 
#### Extract Additional Comments from the Script:
#### 
#### Additional comments may be extracted from the scripts if the
#### comments conform to the "autocontent" technique of commenting
#### scripts.  This technique extracts only those comments embedded
#### within a script which begin with four hash marks followd by 
#### a single space (#### ).  This pattern must also occur at the 
#### beginning of the line.  Any comments which begin with this 
#### pattern are extracted and reformatted as an HTML paragraph.
#### 
#### Multiple paragraphs may be designated within the script by
#### using the (#### ) pattern with nothing following.  This will
#### be interpreted by the "autocontent" generated to mean "insert
#### end of paragraph tag followed by a begin paragraph tag".
#### 
#### Any extracted comment line which ends with a colon ":" will 
#### be enclosed in HTML STRONG tags to make the text bold when 
#### displayed in a browser.
#### 
#### If "autocontent" generates multiple "End Paragraph - 
#### Begin paragraph" pairs, they will be collapsed into a single pair.
#### 
################################################################
      
            grep "^#### " "${TMPFILE}" |
              sed -e 's/^#### //g;s/^$/<\/P><P>/g' |
              uniq |
              sed -e '1,1 s/<\/P><P>/<P>/g;$,$ s/<\/P><P>/<\/P>/g' |
              sed -e 's/.*:$/<STRONG>&<\/STRONG>/g' >&3

################################################################
#### 
#### Add the Date to the end of the Usage Document:
#### 
#### A server-side-include directive that displays the date when
#### the document was generated is added to the end of each document.
#### 
################################################################

            print -u 3 "<P><!--#config timefmt=\"%D\" -->"
            print -u 3 "This file last modified <!--#echo var=\"LAST_MODIFIED\" --></P>"

            print -u 3 "<!-- End \"${FILENAME}doc.${SUFFIX}\" -->"
      
            if (( HTMLOUT == TRUE ))
            then
                print -u 3 "\n<!-- ################################################################ -->\n"

                if [[ -f "${FOOTFILE}" ]]
                then
                    sed -e "s/SCRIPTNAME/${FILENAME%%.*} Shell Script Usage Document/g" "${FOOTFILE}" >&3
                else
                    print -u 3 "</BODY></HTML>"
                fi
            fi

            exec 3>&-
      
        fi    # (( USAGEDOC == TRUE ))

################################################################
#### 
#### Create the Code Document:
#### 
#### Also for each script, an HTML SSI file is created to contain the script
#### source code. This file is named using the file name suffix of the
#### original script up to but not including the first dot ".", followed by
#### ".content.shtml".
#### 
#### The ".shtml" is used so the document may additionally use server-side
#### includes.
#### 
################################################################

        if (( CODEDOC == TRUE ))
        then

            OUTFILE="${DD_TMP}/${FILENAME%%.*}.${SUFFIX}"
            (( STDOUT == TRUE )) && OUTFILE='&1'

            (( VERBOSE == TRUE )) && print -u 2 "# Building ${FILENAME} code document: ${OUTFILE}"

            eval "exec 3>${OUTFILE}"
      
            if (( HTMLOUT == TRUE ))
            then
                if [[ -f "${HEADFILE}" ]]
                then
                    sed -e "s/SCRIPTNAME/${FILENAME%%.*} Shell Script Source Code/g" "${HEADFILE}" >&3
                else
                    print -u 3 "<HTML><BODY>"
                fi
                print -u 3 "\n<!-- ################################################################ -->\n"
            fi

            print -u 3 "<!-- Begin \"${FILENAME}.${SUFFIX}\" -->"
            print -u 3 "<P><H3>Script Source Code for \"${FILENAME}\"</H3></P>"
            print -u 3 "<P>This document contains the source code for the"
            print -u 3 "Disaster Recovery script \"${FILENAME}\"."
            print -u 3 "</P><P><HR></P><P><BLOCKQUOTE><PRE><CODE>"
      
################################################################
#### 
#### Translate special characters into HTML codes:
#### 
#### Any "<" or ">" symbols generated by the usage message or extracted
#### from the script in the additional comments, are converted to
#### HTML recognizable codes that will be interpreted by the web
#### browser when the page is displayed.
#### 
################################################################
      
            cat "${TMPFILE}" |
              sed -e "s/</\&lt;/g;s/>/\&gt;/g;s/\\\&/\\\\\&amp;/g;" >&3
      
            print -u 3 "</CODE></PRE></BLOCKQUOTE></P>"
      
################################################################
#### 
#### Add the Date to the end of the Code Document:
#### 
#### A server-side-include directive that displays the date when
#### the document was generated is added to the end of each document.
#### 
################################################################
      
            print -u 3 "<P><!--#config timefmt=\"%D\" -->"
            print -u 3 "This file last modified <!--#echo var=\"LAST_MODIFIED\" --></P>"

            print -u 3 "<!-- End \"${FILENAME}.${SUFFIX}\" -->"
      
            if (( HTMLOUT == TRUE ))
            then
                print -u 3 "\n<!-- ################################################################ -->\n"

                if [[ -f "${FOOTFILE}" ]]
                then
                    sed -e "s/SCRIPTNAME/${FILENAME%%.*} Shell Script Source Code/g" "${FOOTFILE}" >&3
                else
                    print -u 3 "</BODY></HTML>"
                fi
            fi

            exec 3>&-
      
        fi    # (( CODEDOC == TRUE ))

################################################################
#### 
#### Remove the Temporary Script File:
#### 
#### Remove the temporary script file which was copied or transfered from the
#### source location. The HTML documents were generated using information
#### from  this file.
#### 
################################################################
      
        (( VERBOSE == TRUE )) && print -u 2 "# ${CMD_RM} \"${TMPFILE}\""
        ${CMD_RM} "${TMPFILE}"

        if (( STDOUT == FALSE ))
        then

################################################################
#### 
#### Create the Remote File Transfer Command:
#### 
#### Create the command to perform a remote transfer of the HTML documents to
#### the web server.
#### 
################################################################
      
            CMD="${CMD_CP} -P ${DESTPORT}"
            DESTNAME="${DESTUSER}@${DESTMACH}:${DESTDIR}"

################################################################
#### 
#### Create the Copy Command:
#### 
#### If the destination machine name is the same as the local hostname, then
#### perform a file copy instead of a remote file transfer. Create the
#### command to perform a copy of the HTML documents to a directory on the
#### local host. the web server.
#### 
################################################################
      
            if [[ "_${DESTMACH}" == _*${HNAME}* ]]
            then
                CMD="cp"
                DESTNAME="${DESTDIR}"
            fi

            (( VERBOSE == TRUE )) && print -u 2 "# Copy Command..: ${CMD}"
            (( VERBOSE == TRUE )) && print -u 2 "# local hostname: ${HNAME}"
            (( VERBOSE == TRUE )) && print -u 2 "# DestPort......: ${DESTPORT}"
            (( VERBOSE == TRUE )) && print -u 2 "# DestUser......: ${DESTUSER}"
            (( VERBOSE == TRUE )) && print -u 2 "# DestMach......: ${DESTMACH}"
            (( VERBOSE == TRUE )) && print -u 2 "# DestDIR.......: ${DESTDIR}"
            (( VERBOSE == TRUE )) && print -u 2 "# DestName......: ${DESTNAME}"

################################################################
#### 
#### Copy or Transfer the Usage Document:
#### 
#### Copy or transfer the usage document to the destination location,
#### then remove the temporary file.
#### 
################################################################

            if (( USAGEDOC == TRUE ))
            then
                chmod 644 "${DD_TMP}/${FILENAME%%.*}doc.${SUFFIX}"

                (( VERBOSE == TRUE )) && print -u 2 "# Copying usage document file to destination"
                (( VERBOSE == TRUE )) && print -u 2 "# Destination: ${DESTNAME}"

                (( VERBOSE == TRUE )) && print -u 2 "# ${CMD} \"${DD_TMP}/${FILENAME%%.*}doc.${SUFFIX}\" \"${DESTNAME}\""
                ${CMD} "${DD_TMP}/${FILENAME%%.*}doc.${SUFFIX}" "${DESTNAME}"

                (( VERBOSE == TRUE )) && print -u 2 "# ${CMD_RM} \"${DD_TMP}/${FILENAME%%.*}doc.${SUFFIX}\""
                ${CMD_RM} "${DD_TMP}/${FILENAME%%.*}doc.${SUFFIX}"

            fi    # (( USAGEDOC == TRUE ))

################################################################
#### 
#### Copy or transfer the Code Document:
#### 
#### Copy or transfer the code document to the destination location,
#### then remove the temporary file.
#### 
################################################################

            if (( CODEDOC == TRUE ))
            then
                chmod 644 "${DD_TMP}/${FILENAME%%.*}.${SUFFIX}"

                (( VERBOSE == TRUE )) && print -u 2 "# Copying code document file to destination"
                (( VERBOSE == TRUE )) && print -u 2 "# Destination: ${DESTNAME}"

                (( VERBOSE == TRUE )) && print -u 2 "# ${CMD} \"${DD_TMP}/${FILENAME%%.*}.${SUFFIX}\" \"${DESTNAME}\""
                ${CMD} "${DD_TMP}/${FILENAME%%.*}.${SUFFIX}" "${DESTNAME}"

                (( VERBOSE == TRUE )) && print -u 2 "# ${CMD_RM} \"${DD_TMP}/${FILENAME%%.*}.${SUFFIX}\""
                ${CMD_RM} "${DD_TMP}/${FILENAME%%.*}.${SUFFIX}"

            fi    # (( CODEDOC == TRUE ))

        fi

        (( VERBOSE == TRUE )) && print -- ""

    done < "${AUTOCONTENT}"

################################################################
#### 
#### Environment Variables:
#### 
#### DD_TMP = Directory for storage of HTML SSI files
#### 
################################################################

    return 0
}    
################################################################

autocontent "${@}"

This file last modified 07/04/16

-
Documentation Content Generator
-
 


AIX FREE DEMO UNIX
Automated AIX Deployment
Reduce your DC costs

www.siteox.com

LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com