LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-09-2021, 08:01 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Rep: Reputation: 174Reputation: 174
Handling color coded standard output


Please pardon me if this is the wrong forum. It seems like a simple, fundamental issue - the type which often confuse me.

I am playing with a security scanner called lynis which produces a very nicely formatted and color coded output when I run it at the command line. I now have a LOT of work to do to harden my computer. That said, I would like to get this output into some sort of editor with which I could print it or mark it up as I fix various issues. I can redirect > or tee the output of a lynis scan to a file. So far, so good.

If I cat the file it displays the color coding in the terminal. However, if I open it in a GUI text editor or Libre Office writer I see some gibberish representing the color coding but no color.

lynis may provide some reporting tools. I will look into that. Stil, when I capture std out with color coding from lynis or any other source I would like to have a way to make use of it. Any suggestions?

TIA,

Ken
 
Old 11-09-2021, 09:10 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
The escape sequences you see is what allows there to be colour in the terminal. Commands like cat and less can continue to show the characters in the deisred colour as they are also outputting
to the terminal.

Once you open the file in an editor, you are no longer at the terminal but the escape sequences which produce the colours are now visible.
As the program you open the file in is not the terminal, it would not make sense for the characters to work and you have done nothing to remove them and hence
they appear.

Your alternative would be to tell Lynis to do one verion in colour so you can admire it and a second version without colour so you can work on it in your editor
 
1 members found this post helpful.
Old 11-09-2021, 11:04 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
The package colorized-logs provides ansi2html. So you can convert the Lynis output to HTML, then open it in LibreOffice.

Another similar tool is aha.

Last edited by shruggy; 11-09-2021 at 11:14 AM.
 
Old 11-10-2021, 08:35 AM   #4
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks folks,

I can simply cat the log in a terminal and scroll back and forth. Unfortunately less does not respect the color coding. I may try colorize-logs but I am not at that point yet. I started studying the lynis results at random - looking for places with a lot of red - and found that I had a boatload of old kernels still installed. Apparently autoremove in Ubuntu 20.04 does not correctly remove old kernels. Neither would several scripts and tools I found in my research. I finally ripped the remnants of old kernels out manually with sudo apt remove --purge (kernel).

Now I see that the vast majority of my systemd services are [UNSAFE} I think I need to beat down those concerns before I print out my results for some nighttime reading.

Ken
 
Old 11-10-2021, 08:50 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
less does respect the color coding, just you need to switch raw mode (see man page)
 
Old 11-10-2021, 09:05 AM   #6
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6, CentOS 7 (with Mate), Ubuntu 16.04 Mate
Posts: 2,127

Original Poster
Rep: Reputation: 174Reputation: 174
Thanks pan64,

I figured I might be able to tweak less. At the moment I am overwhelmed with red

Ken
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Standard script output to screen & -x option output to file BoBeau236 Programming 6 05-10-2011 07:43 AM
Color registration bars on output: Lexmark C510 Color Laser printer spud_linux Linux - Hardware 2 10-06-2008 12:46 PM
How do I parse the output of a command that output to standard out? gauol Programming 9 01-17-2008 01:54 PM
what does "standard error was duplicated as standard output" mean? nickleus Linux - General 4 09-15-2006 06:14 AM
Color Coded Vim podollb Linux - Software 5 10-16-2003 04:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration