Erstellen .html-Datei aus dem logfile

Ich brauche ein script, das konvertiert die log-Dateien in leicht sichtbar .html-Dateien zugänglich, die von "jedermann".

Hier ist was ich habe, so weit:

#!/bin/bash

## The purpose of this script is to create .html files from log files, with the ability to optionally GREP for certain strings

if [ "$2" == "" ];
then
        echo "Usage : $0 [Source Log file] [Output HTML file] [String to grep (if applicable)]"
        exit 255
fi;

LOGFILE=$1
OUTPUTFILE=$2
GREPSTRING=$3

if [ "$3" == "" ];
then
        echo "Cat'ing $LOGFILE to $OUTPUTFILE"
        LOGCONTENTS=`cat $LOGFILE`

else
        echo "Grep'ing for $GREPSTRING in $LOGFILE"
        LOGCONTENTS=`grep --color $GREPSTRING $LOGFILE | sed -e "s/^.*$/&1\n/"`
fi;

# Below is the html heading which will be appended to the final .html file
HEADING="<html><body><h1>Log output for: $LOGFILE</h1>"

# Below is the end of the html file
END="</body></html>"

# Below all the prepared variables are stitched together to the OUTPUT/LOG FILE
echo $HEADING > $OUTPUTFILE
echo $LOGCONTENTS >> $OUTPUTFILE
echo $END >> $OUTPUTFILE


# For debugging, enable the lines below
echo $LOGCONTENTS
echo "Done preparing $OUTPUTFILE"

Mein problem ist, dass die Ausgabe, egal wie viel ich Spiele mit CAT, GREP, SED etc., nicht erhalten Zeilenumbrüche. Es ist wichtig für die Ausgabe-Datei zu suchen mehr oder weniger wie bei einem normalen tail-f oder cat.

  • Nur wickeln Sie es alle in <pre> tags, oder Ihre gewünschten CSS-Implementierung derselben.
  • Aber bevor etwas funktioniert, müssen Sie die doppelten Anführungszeichen die Variablen, die du echo.
  • auch alle ändern '==' zu '='
InformationsquelleAutor user2812626 | 2013-09-24
Schreibe einen Kommentar