Also, in order to have the output as HTML, you could pipe the output from your script to something like
ansi2html
.
If memory serves,
ansi2html
is a Python module. But Python should already be pre-installed on all Linux distros. Installing the ansi2html module can be done via your usual package manager, or via pip (
pip install ansi2html
)
And to run it:
Bash:
/path/to/somescript.sh | ansi2html > /path/to/output.html
That will run a script and pipe its output to ansi2html and then redirect ansi2html’s output to a html file.
Where
/path/to/somescript.sh
is the fully qualified/absolute path to the script you want to run.
If you’re running a more localised script in the current directory, you could use a relative path, e.g.:
./somescript.sh
And where
/path/to/output.html
is the absolute path/filename of the output file you want to create. Again, you don’t have to use an absolute path, you could use a relative path.
E.g.
./output.html
, or
../subdir/output.html
You don’t have to run a script. You could also create a bash one-liner that pipes data to several different commands and then finally pipes all of that output to ansi2html to generate an HTML file.
Also, it’s worth running
ansi2html —help
in order to see what additional parameters are available. I haven’t used it in a long while, but there are quite a few options available to format the output.
But using ansi2html without parameters will create a complete, default html page containing whatever input it receives. And it will preserve any coloured/formatted output.