asked on
Log file to html format
Any suggestions on how to go about accomplishing this? Thanks Experts.
ASKER
Found this at: https://stackoverflow.com/questions/15675718/windows-batch-file-scripting-keep-formatting-in-html
@echo off
echo ^<pre^> >>index.html
netsh firewall show config >> index.html
echo ^</pre^> >>index.html
Thanks for the reply Abdul. Take care!
How does that solve/relate to putting "links" in the log file output???
ASKER
ASKER
ASKER
Well, there's a little more to writing a real HTML file out for the log data, likely wrapping it in <HTML> tags, etc.
You could use the <a> tag to create links to other parts of the file (page). The challenge will just be escaping certain characters that are "special" in a BAT file, but need to be in the HTML version.
Also, closing the question 24 minutes after you posted it doesn't really give experts a chance to find and comment on it.
I don't know how you are generating the log data, or what links you envision, but the challenge could be knowing what those destinations will be further down in the file when you start writing the file, so you can create the links at the top of the file.
Glad you found your own solution to this question, good luck.
ASKER
We've worked together before and I've always found your solutions to be incredibly top tier and brilliant, if not quick and precise. Hopefully we get to work together again in the future. Take care.
@echo off
setlocal EnableDelayedExpansion
rem Define log file location
set LogFile=log.html
rem Delete old log file if it exists
if exist "%LogFile%" del "%LogFile%"
rem HTML document headers
echo.^<html^>>>"%LogFile%"
echo.^<a name="top"^>^</a^>>>"%LogFile%"
echo.^<head^>>>"%LogFile%"
echo.^<title^>^<h1^>Example LOG file in HTML^</title^>^</h1^>^</title^>>>"%LogFile%"
echo.^</head^>>>"%LogFile%"
echo.^<body^>>>"%LogFile%"
echo.^<p^>Date: %DATE%^</p^>>>"%LogFile%"
echo.^<p^>Time: %TIME%^</p^>>>"%LogFile%"
rem Links to sections furth down log file
echo.^<ul^>>>"%LogFile%"
echo.^<li^>^<a href="#section1"^>Section 1^</a^>^</li^>>>"%LogFile%"
echo.^<li^>^<a href="#section2"^>Section 2^</a^>^</li^>>>"%LogFile%"
echo.^<li^>^<a href="#section3"^>Section 3^</a^>^</li^>>>"%LogFile%"
echo.^</ul^>>>"%LogFile%"
rem Leave a little room
echo.^<p^>^</p^>>>"%LogFile%"
rem Define target section and put some sample data there
echo.^<a name="section1"^>^<h2^>Section 1^</h2^>^</a^>>>"%LogFile%"
for /l %%i in (1,1,50) do (
echo.Sample log data. %%i - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^</br^>>>"%LogFile%"
)
echo.^<a href="#top"^>Back to top^</a^>>>"%LogFile%"
rem Define target section and put some sample data there
echo.^<a name="section2"^>^<h2^>Section 2^</h2^>^</a^>>>"%LogFile%"
for /l %%i in (1,1,50) do (
echo.Sample log data. %%i - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^</br^>>>"%LogFile%"
)
echo.^<a href="#top"^>Back to top^</a^>>>"%LogFile%"
rem Define target section and put some sample data there
echo.^<a name="section3"^>^<h2^>Section 3^</h2^>^</a^>>>"%LogFile%"
for /l %%i in (1,1,50) do (
echo.Sample log data. %%i - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^</br^>>>"%LogFile%"
)
echo.^<a href="#top"^>Back to top^</a^>>>"%LogFile%"
rem HTML document wrap up
echo.^</body^>>>"%LogFile%"
echo.^</html^>>>"%LogFile%"
Try to make it simple and open the logs using Notepad ++