Setting Default Browser in Linux When Things are Stubborn

Running XFCE4 and setting the preferred applications generally works. However, I noticed that some applications still would not listen to my demands of using a specific browser when launching links. For example, using python’s webbrowser module, and therefore almost any other module opening external links, would use Firefox or Opera (depending on which was available).

# Checking python invocation of a browser
import webbrowser as w

Here’s the culprit, check in your /etc/alternatives/ directory and you’ll see what I mean.

ls -l /etc/alternatives/

Notice the entry x-www-browser. This will be a symlink to a browser and this value was different than what I was attempting to set through the XFCE4 GUI configuration. This problem seems somewhat common as I’ve seen it occur in KDE and GNOME as well.

To fix this issue, simply run the following command and you should be presented with a list of browsers from which you can set.

# Update your browser choice and choose from the presented text menu
sudo update-alternatives --verbose --config x-www-browser

# Now make sure teh proper symlink is setup
ls -l /etc/alternatives/x-www-browser

Now you should have a functional default choice. Those GUIs can suck it!

Analyzing Brute Force Attempts in BASH

If you have a public facing SSH server running on the standard port, your message log is probably filled with failed authentication attempts from brute force attacks. Let’s mash up some quick BASH commands to analyze this data. For our purposes, we’ll look at the top attacker IPs and the top usernames tried.

First, pull down all of your message files and decompress them in a working directory using bunzip2.

Once you have all your message logs ready, we will search through them and pull out all of the authentication failure entries and grab the IP and username for each attempt.

grep -r "authentication error" messages* | awk '{split($0,a," "); print a[NF],a[NF-2]}' > attempts

So we first use grep to look for failed authentications by searching recursively for the string “authentication error” in all of our message logs by using the wildcard. We then pipe this to awk and split each input line found into an array delimited by a whitespace. The last part of each line, and therefore our new array, goes something like: ‘authentication error for USERNAME from IP’. So to get the username and IP from our array we can use the array length variable NF and use that to index the variables we need. Here we grab the last using a[NF] and two in from that with a[NF-2]. Finally, we output this to a file called attempts.

Now, let’s use more BASH magic to do the analyses for us. Our attempts file now is in the format as follows: IP USERNAME. We want to see the top IPs and usernames and we can do that with some sorting commands.

cut -d ' ' -f2 attempts | sort | uniq -c | sort -nr > attempts_username
cut -d ' ' -f1 attempts | sort | uniq -c | sort -nr > attempts_ip

Here, we simply grab either the username in the second column or the IP in the first with cut, sort this data, prepend lines with the number of occurrences of each, and then sort by this occurrence number and output to a new file. You can now view attempts_username and attempts_ip to see the top usernames and IPs, respectively, of brute force attacks.

Lastly, we can associate the keep usernames and IPs together and sort on one or the other to see the correlation between the two. To end our initial analyses, we will sort on usernames and find out for the top attempted usernames, what are the top originating IPs.

 sort -k 2,2 attempts| uniq -c | sort -nr | head -n 10

Next time we will be using some GEOIP methods to see where our top attack attempts are originating.

Bash Snippet for Git Users

Keeping track of what branch you are using while in a git repository can be a bit of a pain. Adding the following code to your ~/.bashrc file can make it a bit easier since it will prepend your prompt with the current branch.

function parse_git_branch {
    GIT_BRANCH=$(git branch --no-color 2> /dev/null | awk '{if ($1 == "*") { printf "(%s) ",$2}}')
    PS1="$GIT_BRANCH\[email protected]\h:\w\$ "

Here it is working:
[email protected]:~$ source /etc/bash.bashrc 
[email protected]:~$ cd programming/bits
(master) [email protected]:~/programming/bits$ 

Migrating to XFCE

The following was from a Google+ post that I figured I would share here as well.

Well I think I’m finally switching my main desktop from KDE to XFCE. Too much flash and pizazz and having to turn off behaviors and mannerisms for my liking. I guess I’m just getting too old for these young peoples’ desktops.

It was a decent 9+ years, KDE. Sorry you had to turn into GNOME.

A later follow-up comment:

[warning: non-proofread, off-the-cuff rant ahead]

Made the switch last night. Very refreshing!

Not sure if others get the same feeling, but I believe desktops have a measurable weight in terms of interaction and feel. As of late (read KDE 4.*), KDE has lost weight and felt ungrounded. Delayed click responses, bouncing icons, crashing UI effects, windows partially disappearing, and the ‘improved’ graphics all tend to lend way to a flighty feel and experience. But not in a good way, but rather a lack of solidity that I want from a desktop. I want a concrete user experience that shows of it’s strength in the back-end by portraying a solid and consistently reliable front-end. I’ll trade ‘sleek’, ‘cutting-edge’, and ‘feature overflowing’ for solidity and reliability any day. When productivity calls what really matters?

Is it just me feeling the departure of usability? I am one who spends 75% of my computing time tied to a terminal emulator. Maybe I am simply disconnected from what is truly meant to be the modern desktop experience. I look to OS X and Windows Vista/7 for comparison and see similar qualities to KDE 4 and GNOME 3. It’s quite possible that these are the ways of today and are in response to what the majority of users demand from their desktops.

One of the major selling points for Linux is obviously the stability and reliability of the kernel. Therefore, I would expect that the layering OS and desktop should reflect such qualities and do nothing but to bring out the best possible performance and usability of the Linux kernel. KDE4 and GNOME3 seem to have diverged greatly from these ideas. Is it time for distributions to begin defaulting their OSes to a more reasonable (see qualities above for a definition of reasonable) desktop? Maybe Xubuntu should really become Ubuntu, leaving Kubuntu and Gubuntu (?) as unique, non-default variations.


Python – Dynamically Printing to Single Line of Stdout

It’s that time again; code snippet time. This is a short and sweet bit of a code that has some really practical and powerful implications.

When handling large amounts of data processing, it’s often desirable to keep the user informed of where things are in terms of progress. However, filling up the scrollback buffer with thousands of “Completed processing [item X]” or “X % completed” is not always desirable. So, how do we handle verbosity without filling scrollback?

Here, we will print data using stdout but we will continually use the same line of the terminal. It’s extremely simple; before each data print, we will move the cursor back to the beginning of the current line, cut out the entire line of text, and then print our current bit of data.

*Note: This is using ANSI escape sequences and therefore will work on any VT100 type terminal.


The code:

import sys

class Printer():
	Print things to stdout on one line dynamically

	def __init__(self,data):



To output data we might do something like:

totalFiles = len(fileList)
currentFileNum = 1.0

for f in fileList:
	currentPercent = currentFileNum/totalFiles*100
	output = "%f of %d completed." % (currentPercent,totalFiles)
	currentFileNum += 1


And here is an example of what our output would look like in a practical scenario.

Processing some data
Progressing along with dynamic status updates

Simple. You can test it out using an ‘for x in range(1,100)’ sort of statement as well. Now we can keep a persistent display of data processing or program progress without slamming the scrollback buffer of the user’s terminal.

Installing Google Chrome in Slackware 13 (13.37)

Trying to install Google-Chrome via RPM (with rpm2tgz) will give you an error with libnss3. Don’t fret, there is already a way to build Google-Chrome without much effort. Below is a quick way using the mirror from Penn State (carroll), but if you have your install media, you can find the same files there in /extra.

Go to:

The README file is pretty self explanatory, but essentially you want to do the following:

  1. Become rootSetup a build directory (mkdir chrome && cd chrome)
  2. Wget these files: [ ] [ ] [ ] [ ]
  3. Change execution bit on slackbuild file and run it (chmod +x google-chrome.SlackBuild && ./google-chrome.SlackBuild)
  4. Go to tmp and install the file (cd /tmp && upgradepkg –install-new google-chrome.txz)
  5. Go back and install the other files (cd /root/chrome/ && upgradepkg –install-new *.txz)

Now you should have a fully functional google-chrome install.

AmazonMP3 and Linux – Clamz

Amazon’s MP3 download store is a very well stocked and typically well priced source for your MP3 music needs. The files free of DRM and are offered up a nice quality without having to pay extra like with iTunes Plus.

In order to download all songs in a single go and receive the full album discount, you need to use the AmazonMP3 download client. The great bit is that a Linux client is offered, and there are several versions packaged up for various distributions, however, these are often hit or miss. There are usually workarounds and methods to get the dependencies you need, but there is a better solution.

Clamz is the hands down way to go. Free and open source, Clamz is a great command line client to download your AMZ files (the full album versions of the downloads).

Head to Clamz project page linked to above, compile and install as usual, and then head over to this link to activate Clamz with your browser.

Now you can One-Click buy your albums. You’ll receive the AMZ file for download which you can then grab your music with something simple like:

mkdir new_album && cd new_album && clamz [thefile].amz

Besides the simple grab as highlighted above, you can do a few other things with Clamz:

$ clamz --help
Usage: clamz [options] amz-file ...
General options:
 -o, --output=NAME:       write output to file NAME (may contain
                          variables, see below)
 -d, --output-dir=DIR:    write output to directory DIR (may also
                          contain variables)
 -r, --resume:            resume a partial download
 -i, --info:              show info about AMZ-files; do not download
                          any tracks
 -x, --xml:               output XML data from AMZ-files; do not download
                          any tracks
 -v, --verbose:           display detailed information
 -q, --quiet:             don't display non-critical messages
 --help:                  display this help
 --version:               display program version

Output options:
 --allow-chars=CHARS:     allow filenames containing CHARS
 --forbid-chars=CHARS:    forbid filenames containing CHARS
 --allow-uppercase:       allow uppercase letters in filenames
 --forbid-uppercase:      forbid uppercase letters in filenames
 --utf8-filenames:        allow UTF-8 filenames
 --ascii-filenames:       force ASCII-only filenames

Filenames (-o, -d) may contain the following variables:
 ${title} ${creator} ${album} ${tracknum} ${album_artist} ${genre}
 ${discnum} ${suffix} ${asin} ${album_asin}

As you can see, Clamz gives you a lot of power over your downloads that you don’t have with the Amazon client [note: it’s been a year or two since I’ve used the Amazon client, things may be different now]. This inevitably leaves you with the ability to create batch processing of your AMZ files if you are downloading a lot of music in a single go. Just download all your AMZ files and then create a simple shell script around Clamz to download all your files to corresponding directories. Splitting out to proper directories could easily be done by reading in parts of the AMZ XML using Clamz with the –xml switch and grabbing any information you might want to use.

Clamz is a must have for those that purchase music from Amazon.  Fast, simple, and essentially foolproof.

Amazon Prime Streaming – Another Netflix Alternative for Linux?

Amazon announced this week that Prime users would now have access to a pool of free content to stream instantly from the video-on-demand portion of their website.

While the content might not be the latest and greatest blockbuster movies and shows, it is a substantial amount of content and worthy to be considered a viable contender for the streaming market. Take a look at the Netflix instant content pool. It’s pretty substantial now, but it still does not contain the latest movies (which are home rental only for the most part). Also consider that when Netflix instant started it was a rather meager offering of mostly meh content. Given such, it might be a sign of possible things to come for Amazon streaming.

Prime being a $79 a year opt-in might seem steep. If you are already a prime member, then it’s a moot point or better, further validates your spending $79 a year so you can get that video game on release date for free or so you can get that $10 paperback second day without having to pay the sub-$25 shipping penalty. If you aren’t a prime member, this seems like a great time to jump in. Along with awesome shipping, you can now stream movies and television instantly as well.

Still not sold? Here’s the cool part for us linux (or *BSD, etc) guys and girls: streaming is system independent, and so far seems to also be browser independent. Can you view Flash? Then you should be ready to roll watching Amazon’s instant content.

Now with Hulu (and Hulu-desktop) and Amazon instant being friends of an operating system independent approach, will that push Netflix along to allow all of us paying customers with Linux to utilize the instant features? Or will Netflix keep it’s head buried in the sand and stay cozy with Microsoft? Remember when we thought Flash was so evil, well looks like Silverlight has trumped that by leaps and bounds.

Before ending, I’ll make a quick note on performance. As of now, streaming is around 480p (supposedly). I’ve tested it out on two media PCs both running linux; Fedora setup connected to a 50″ plasma via HDMI and an Xubuntu setup connected to a 32″ CRT via s-video. Both setups streamed very nicely, and while it obviously isn’t in HD, even on the 50″ television, the quality was just fine. The big positive performance point (sorry) was that there was not a single buffer wait, stutter, or hiccup in the stream. Granted, this isn’t a very scientific comparison, but I wouldn’t be surprised to see the power of Amazon shining through in the technical side of the streaming business. I mean they already figured out a nice way to stream content without sleeping with Microsoft to keep the bad guys from ripping content. [Update: There are HD options available. The Best of NOVA #6 and Yellowstone are both offered in an HD version and looked and streamed great.]

Prime member? Check it out. Not a Prime member? Seems like  a great time to join in, especially if you are a frequent Amazon shopper.