ansifilter – ANSI control sequence converter

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.

Fedora 19 alpha is a Go

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:

  • Bind 10 – completely rewritten from scratch, and bringing both DNS and DHCP in one handy package.
  • Developers Assistant – the description is rather vague, but overall it sounds useful.
  • KScreen – finally I won’t have to reconfigure the second monitor every time I reboot the laptop.
  • MATE Desktop – I loved Gnome 2.  If Gnome 3 and KDE 4 won’t get significantly better by the time of the release, I will probably switch to MATE.
  • Node.js – I wanted to play around with it for a while now, but never got the time to get it on my box.  Maybe now I will.
  • PHP 5.5 – new PHP is better PHP.
  • Replace MySQL with MariaDB – that’s an interesting move. I wonder how much trouble this will create with MySQL still being on the servers.
  • Ruby 2.0 – Similar to Node.js, this just makes it so much easier to try new things.

So, this looks like a busy release.

Accessing current username in sudo scripts on CentOS

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.