2

I was using "ansi2html.sh" here http://www.pixelbeat.org/scripts/ansi2html.sh to get my job done.

ls -lrt /web/htdocs | tail -12 | ./ansi2html.sh --bg=dark >test.html

I was using ansible on local host having Linux OS to run this across multiple hosts which generated the html files on each of the remote hosts and then i would finally pull all the html files from all remote to my local ansible server.

This worked fine for all Linux systems.

However, "ansi2html.sh" has dependency of gawk which is not present on a set of production AiX 6.1 and 7 system.

I get this error:

./ansi2html.sh[38]: gawk:  not found

As my AiX is hosting the production application; installing gawk is not recommended.

I dont know if the solution could be to get the output of ls -lrt from all AiX host and then feed that output to "ansi2html.sh" on the local ansible linux server having gawk. Not sure if this will work and if so how ? Note: i wish the output to have the same look and feel as on the putty terminal prompt.

Can I get a solution for AiX so i could use ansible to get html files with the output of ls -lrt from across all AiX hosts ?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Ashar
  • 2,942
  • 10
  • 58
  • 122
  • In your Linux box: `ssh user@aixhost 'ls -lrt /web/htdocs | tail -12' | ./ansi2html.sh --bg=dark >test.html` – Lorinczy Zsigmond Feb 29 '20 at 13:51
  • This solution works. However I will post another question to make this solution work using Ansible. Can you please put this as an answer @Lorinczy Zsigmond – Ashar Feb 29 '20 at 14:00

2 Answers2

2

Using aha Ansi HTML Adapter for this task, works very well:

ls -lrt ~ | tail -12 | aha --black --title "Home list"> ls.html

Example using html2text

curl https://stackoverflow.com/questions/60465150/how-to-convert-terminal-output-to-html-file-format | html2text | aha --black --title "the SO question"> txt.html

Install:

sudo apt install aha
sudo apt install html2text

This is possible to convert ANSII encoding using iconv: Force encode from US-ASCII to UTF-8 (iconv)


Lastly, all that is also doable from php alone, which should works everywhere. Quick base to convert html to text using php:

php -r 'echo htmlspecialchars(trim(strip_tags("<div> <b>Hello</b> world</div>")));'
// Hello world

ANSII to text from php using REGEXes:

$ansii = " |[0m [34m▓▓▓▓▓[0m";
echo preg_replace("/\x1B\[[0-9;]*[JKmsu]/","",$ansii);

https://stackoverflow.com/a/59060531/2494754

NVRM
  • 11,480
  • 1
  • 88
  • 87
  • Installation is discouraged on AiX as mentioned in the original post. I can grab the output from AiX to Linux and then process it if that will work as a solution? Please suggest. – Ashar Feb 29 '20 at 13:30
  • Ok, then it won't be easy. This is doable using only php. Added a base example. – NVRM Feb 29 '20 at 13:45
2

(Already written as comment) You can use ssh to execute a command on the remote computer and process the output on the local computer. Example:

ssh user@aixhost 'ls -lrt /web/htdocs | tail -12' |
./ansi2html.sh --bg=dark >test.html

Standard input can be redirected, too, e.g:

ssh user1@host1 'cd frompath; tar -czf - sendme/' |
ssh user2@host2 'cd topath; tar -xzf -'

Note: I know nothing about Ansible, but I heard that with it you can do almost everything you could do without it.

Lorinczy Zsigmond
  • 1,749
  • 1
  • 14
  • 21