Thursday, October 2, 2008

Lost in a sea of terminals

Usually I enjoy my screen being covered with a variety of terminals across multiple servers. But on occasion, I type utterly the wrong thing, in utterly the wrong place, and calamity ensues.

So to provide a slight buffer against this, I made a change in my bash prompt. It clues me in if I am on a remote server, a non-personal machine if you will, on which I need to exercise more caution before beating the enter key:
Just something noticeable, but not overly intrusive. Won't stop idiocy, of course, but it can't hurt.

To make it work:

# Prompt with easier to read coloring. Define and check for safe boxes:
declare -a LOCALBOXES[0]="MyBox1" LOCALBOXES[1]="MyBox2"
for box in $LOCALBOXES
if [[ $CURRENTBOX = $box ]] ; then
PS1="\[\033[0;31m\][\T]\[\033[0;36m\]\u@\[\033[1;33m\]\H \[\033[1;34m\]\w: \[\033[0m\]"
PS1="\[\033[1;36m\]**REMOTE**\[\033[0;31m\][\T]\[\033[0;36m\]\u@\[\033[1;33m\]\H \[\033[1;34m\]\w: \[\033[0m\]"

Monday, September 22, 2008

ack: grep but better!

I came across ack today, and now grep is sleeping outside. It's very much like grep, except it assumes all the little things that you always wanted grep to remember, but that it never did. It actually left the light on for you, and put the toilet seat down.

Anyway, there were some rough bits with installation. On Ubuntu, it is installed by sudo apt-get install ack-grep. If you think, hey, I will take the obvious path and install "ack"! You will be thinking with wrongitude. For ack is, in fact, a Kanji code converter, which I discovered after not a little anger. On RHEL, CentOS, and the like, you have to install with cpan -i App:Ack.

Once installed, just try some ack-grep STRING.
Want to ignore .svn dirs? It already did. Want to recursively search? It already did. And it brought over a bag of chips. Read the Top 10 for more goodies.

Oh, and don't forget to add ack-grep --thpppt to exit your shell scripts:

Monday, August 11, 2008

Wordpress contact forms and mailing made less complicated

After setting up some Wordpress blogs on my own server, I ran into the problem of wanting a basic contact form that would email myself and users. I in no way wanted to bother setting up my own mail server. I also would prefer not buying SMTP mail service. After a wretched chain of annoying plugins, I came across a salutary trio that met my needs: Cimy Swift SMTP, Contact Form 7, and a Gmail surprise.

Cimy Swift SMTP allows you to setup SMTP settings, which is perfect if you want to use an external service and not use PHP mail() function. Apparently, Google will let you send mail to any address from any domain using SMTP. Handy! So you just install Cimy, go to its Settings page, put in "" as SMTP server, port 465 (it tells you this is for Gmail), your Gmail user and pass, and that you want TLS (it also notes this is for Gmail. Save, put in a test address, and it should just work. At least it did for me, where others failed.

Now you are all dressed up with SMTP, but where to go? I tried a number of contact form plugins that looked great, had lots of features, etc. And none of them bothered using the SMTP settings I put in. Contact Form 7 did, however. It's simple, and takes a little customization to make it look decent. But still, it is a basic contact form that works, and that is all I needed.

Wednesday, July 16, 2008

Needs more cow...say!

I stumbled across a wonderful program today: cowsay! It is just as cool as you would imagine:
cowsay "Text"
gives you an ASCII-art cow saying your Text.

I think I will use it as the welcome banner on all my servers:

Thursday, July 10, 2008

Handy Network Utilities: nast, fping

I discovered a wonderful utility last night: nast. I wanted to scan my local network, just to see what devices were on it, what their addresses were, etc. I could ping my entire subnet, but what if I had a machine that rejected ICMP packets? (Not that I do very often, but it can happen in larger environments). I thought using a protocol like ARP would be much more robust, since it is pretty much guaranteed to be available. Then I discovered nast.

nast can do a lot of neat things. The first I found was mapping a subnet of course, which you can do by running
sudo nast -i eth1 -m
adjusting the interface to fit. It will return something like:
Nast V. 0.2.0

Mapping the Lan for subnet ... please wait

MAC address Ip address (hostname)
00:19:D2:92:20:CE (MyGateway)
00:1B:C0:B7:86:CB (MyBox) (*)
00:14:38:E5:76:10 (SomeOtherBox)
nast can also try to find out if there are any nodes on your subnet acting in promiscuous mode, which I think is pretty hot. Check out the main nast page for the full feature set.

In my searching, I also came across fping. Its main improvements over regular old ping are:
  • More than one host can be passed (as well as a file containing hosts)
  • Its output is very simple and easy to parse, making it ideal for scripting
  • It tries each host and moves on if there is no response, making the whole process faster
Instead of
ping -c 1 myhost1 ; ping -c 1 myhost2
you can just run
fping myhost1 myhost2
which just returns
myhost1 is alive
myhost2 is alive
Both nast and fping are available in the Ubuntu repos.

Wednesday, July 9, 2008

Crashing Application Greeter

I was playing around with themes and the like in Hardy Heron recently, and I ended up selecting a new login screen. Apparently, something was wrong with the one I installed, however, since the next time I went to login, I was presented with a black screen and the message "The greeter application appears to be crashing. Attempting to use a different one." Hitting Ok on this merely cycled through X starting up and led to the same message.

To fix this, I went into another tty with Alt + F2, logged in, and ran "sudo vim /etc/gdm/gdm.conf". I commented out the line "Greeter=/usr/lib/gdm/gdmgreeter" and added "Greeter=/usr/lib/gdm/gdmlogin". After restarting, a simple Gnome login screen appeared fine, which allowed me to get in and change the login screen to a know safe default.

Tuesday, July 8, 2008

Additional Tips for GNOME-Do

After having played with GNOME-Do for a few days, experiencing some pain and finding more fun things, I have some suggestions that may make your adoption of it smoother.
  • Get to 0.5. 0.4 will likely be in your repo, so beware! It is a paltry substitute. If you have installed that, remove it and delete the plugins dir. Then add the repos to your "/etc/apt/sources.list" as described here, then run "sudo apt-get install gnome-do". Also, make sure you kill GNOME-Do if it is running, BEFORE you remove the old version and try to install.
  • 0.5 has a lot of great features, mainly the built-in Preferences window, which lets you just check plugins you want. There is also a new Open With action, which comes in very handy. Get to 0.5.
  • Very neat plugins: Skype (lets you chat or call with Skype contacts, like the Pidgin plugin), Upload to Flickr, Locate Files, Rhythmbox.
  • Install "xclip" (is in repos). This will let you select any text, invoke GNOME-Do, and act on that text.
Once I got to 0.5 and got those plugins running, GNOME-Do started becoming even handier!

Thursday, July 3, 2008

Killer App: GNOME-Do!

I started to doubt my beloved Ubuntu after a co-worker showed me the various virtues of Quicksilver on the Mac. But, I have... Beagle? Yuck. Lunchbox was cute, but never seemed to work right. But today, I take that doubt back, great Linux gods. Behold: GNOME Do!

If you know what Quicksilver is, then you are basically there. If you don't, just imagine a pretty app launched by a simple key combo that lets you do anything from open files, to play songs, to email people with just a few easy keystrokes.

David Siegel's beautiful site has lots of documentation, plugins, and more. Just be on Gutsy or Heron, add a repo to your sources, install. In case you don't know what "super-space" is, as I didn't, super is the meta key, so the one with a Windows Logo on it on most keyboards.

Some additional plugins I installed and found handy:
  • - Search your bookmarks and public ones
  • Rhythmbox - Play songs in your library, control volume, and more
  • Pidgin - IM people in your Pidgin lists

Wednesday, July 2, 2008

Handy script: LAMP stack version printer

Often when troubleshooting or setting up servers, I need to know the installed versions of applications commonly grouped into the "LAMP" stack. I dislike having to remember the slight differences between them when trying to coerce each to divulge their version. So I created a script that does that, and even prints it all in easy-to-read colors!

The code:
# Written by Samuel Huckins
# July 2007
# Prints out version info for
# things in the LAMP stack.
echo -e "\e[1;34mThis machine's LAMP stack:\e[0m"
echo ""
# Linux:
LINUX=`cat /etc/issue`
echo -e -n " * \e[31mL\e[1;33minux: \e[0m"
echo "$LINUX"
# Apache:
echo -e -n " * \e[31mA\e[1;33mpache: \e[0m"
if [ -e /usr/sbin/httpd ]
echo "`/usr/sbin/httpd -v| head -n 1 | awk '{print $3}'`"
elif [ -e /usr/sbin/apache2 ]
echo "`/usr/sbin/apache2 -v| head -n 1 | awk '{print $3}'`"
echo -e "\e[37mNot present\e[0m"
# MySQL:
echo -e -n " * \e[31mM\e[1;33mySQL: \e[0m"
if [ -e /usr/bin/mysql ]
echo "`/usr/bin/mysql --version | awk '/Ver/ {print $2, $3, $4, $5}' | sed 's/,//'`"
echo -e "\e[37mNot present\e[0m"
# PHP:
echo -e -n " * \e[31mP\e[1;33mHP: \e[0m"
if [ -e /usr/bin/php ]
echo "`php -v`"
echo -e "\e[37mNot present\e[0m"
# Perl:
echo -e -n " * \e[31mP\e[1;33merl: \e[0m"
if [ -e /usr/bin/perl ]
echo "`perl -v | awk '/This is perl/ {print $4}' | sed 's/v//'`"
echo -e "\e[37mNot present\e[0m"
# Python:
echo -e -n " * \e[31mP\e[1;33mython: \e[0m"
if [ -e /usr/bin/python ]
echo "`/usr/bin/env python -V 2>&1 | awk '/Python/ {print $2}'`"
echo -e "\e[37mNot present\e[0m"
# done
echo ""
The result:

Call it "", and add something like "alias lamp="~/my/code/". Couldn't be easier.

Minor caveat: While the script does check each program for existence, I only check the most common place. It could be better expanded to cover less used locations for applications, conventions on more OSes, etc.

Wednesday, October 31, 2007

Reference script for CLI color codes

I have been experimenting with adding more color to my bash prompts of late. I find it easier to read when the fields are in distinct colors. The problem I always have is remembering what those wonderfully obscure ANSI escape sequences represent. I always have to look at a table to remind myself that "light red" maps to "1;31".

In an interesting guide to configuring your bash prompt that I have been going through, there was a script listed that makes this much easier:
# This file echoes a bunch of color codes to the
# terminal to demonstrate what's available. Each
# line is the color code of one forground color,
# out of 17 (default + 16 escapes), followed by a
# test use of that color on all nine background
# colors (default + 8 escapes).

T='gYw' # The test text

echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";

for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
This is from the Bash Prompt HOWTO, from a script by Daniel Crisman. It produces the following when run:

Just add an alias like alias colors="~/dir/of/handy/scripts/", and you can be reminded whenever you like.

I am still experimenting with my prompt colors, but differentiating the fields I find useful has made things a lot easier: