ansifilter – ANSI control sequence converter
This handy utility is useful for when you need to convert some text with ANSI control sequences into plain text or some other format, like HTML. While there, also have a look at highlight script.
Linux is my primary operating system. I used it on the servers, desktops, laptops, netbooks, and even mobile phones since approximately 1997. I’ve tried a number of distributions over the years, and even created a couple myself. I still look around sometimes to see what others are up to. But most of my machines are running some sort of Red Hat – either a quick and easy Fedora Linux, or a stable and secure Red Hat Enterprise Server, or a cheaper CentOS alternative.
And while by now I am very comfortable in the Linux environment (both graphical and command line), I still discover a lot of new and interesting things about it. When I come across something worthy, I usually share it with the rest of the Open Software world, using this category.
ansifilter – ANSI control sequence converter
This handy utility is useful for when you need to convert some text with ANSI control sequences into plain text or some other format, like HTML. While there, also have a look at highlight script.
Open source is taking over the software world
Survey results that are not surprising at all, and yet help me have a smile on my face when I fall asleep…
Fedora 19 alpha version will be released next Tuesday. I’ve been busy with other things recently, so that was a surprising announcement for me. Is it that time of the year again? Apparently. We are still a good three month away from the final release, but it’s still good to hear that there is progress. Looking over the features for this release, I find these interesting:
So, this looks like a busy release.
This, though not enough for me to stop disabling SELinux, is still eye-opening.
I got a bit of a puzzle at work today. I had a script that was executed as another user via sudo, but I wanted to access the original username in the script, to know who was executing it. Sudoers manual suggest working with “Defaults env_keep“. Looking into the /etc/sudoers, I noticed that $USERNAME variable was whitelisted (in line #3 below):
Defaults env_reset Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS" Defaults env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE" Defaults env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES" Defaults env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE" Defaults env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"
So, I tried to use the $USERNAME variable in my script but it was coming up with empty results. That made me look deeper into default Bash initialization, and I found out that $USERNAME variable setup wasn’t a part of it. However, $LOGNAME was (in /etc/profile). I think, so few people actually use it that nobody noticed or bothered about it until now. Anyway, the solution now was obvious – simply add $LOGNAME variable to the sudo white list. Appending this line to the above env_keep ones did the job:
Defaults env_keep += "LOGNAME"
There. In hopes it will help future generations…
P.S.: All that happened on a more or less default installation of CentOS 6.3, but I’m sure other Red Hat based distributions have a similar issue.
P.P.S.: If your script is ALWAYS invoked via sudo, also have a look at $SUDO_UID, $SUDO_GID, and $SUDO_USER variables.