We help IT Professionals succeed at work.

Log file to html format

samiam41
samiam41 asked
on
Experts, we have a batch script that we run on a user's pc to aid in trouble-shooting.  The script echo's out the results to a log file but as we gather more info and put it into the log file, it's becoming a bit lengthy.  If I could put it into an html format, I'd like to be able to jump to different sections by links.  

Any suggestions on how to go about accomplishing this?  Thanks Experts.
Comment
Watch Question

Abdul Jalil Abou AlzahabConfiguration Manager & Windows 10 Administrator

Commented:

Try to make it simple and open the logs using Notepad ++

Author

Commented:

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!

Commented:

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


Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:

How does that solve/relate to putting "links" in the log file output???

Author

Commented:
If you know how to add the links, I am more than willing to ask a new question that you can provide insight/code to.  Let me know.

Author

Commented:
Bill Prew, the question I asked how to get the log file into an html format SO THAT I could add links.  I need the carriage before I start working on the horse.  If I didn't get the format into html, not sure how I could start on the links.

Author

Commented:
Sounds like we're moving on then.  Thanks again all.
Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:

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.

Author

Commented:
I've left questions open before for days with no input from experts.  Time doesn't reflect the likelihood of higher chance of involvement, in my history.  Not that an explanation for closing the ticket is necessary but I had spent 20 minutes looking for an answer before posting the question.  Once I found the answer, I didn't want to waste any expert's time on providing an answer.  That would have been worse manners I'd thought.

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.
Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:
Worked this up very quick, but should give you some additional ideas on how this could all fit together.  I didn't spend much time on formatting it pretty, but shows how you could link to additional sections.

@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%"

Open in new window