Archive for December, 2006

Console Bandwidth Monitors: nload & bwm-ng

Friday, December 15th, 2006

I was wondering what nifty utilities were available for monitoring my bandwidth from the console. After a few minutes of googling I found my answer. There were two options that I found right away, bwm-ng and nload. Both programs have similar features so it really came down to look. Since I was slightly happier with nload, I installed it on all of my full-time Linux machines, this included Fedora 6, Ubuntu Edgy and a Debian Sarge server. Don’t take my word for it though, if you have a hankerin’ to monitor your bandwidth, check them both out.

The screen-cap below is shows nload and a few other programs running. The first row is the local machine (FC6), the second row is (from left to right) a Debian Sarge server and an Ubuntu Edgy desktop. The third row shows an available console and an scp command transferring a file from the Fedora box to the Debian box.

Bandwidth Monitor

Installing on Ubuntu:

Be sure that you have the Universe repo enabled (click here for help)

sudo apt-get install nload bwm-ng

Installing on Fedora:

Installing an nload package on Fedora requires adding another repo to your yum configuration. The steps are below.

1: First create the dries.repo file as root. If you aren’t a Gnome user, you can substitute gedit with kwrite or kate below.

su -c 'gedit /etc/yum.repos.d/dries.repo'

Paste the four lines below into the editor, save and exit:

[dries]
name=Extra Fedora rpms dries - $releasever - $basearch
baseurl=http://ftp.belnet.be/packages/dries.ulyssis.org/fedora/linux/$releasever/$basearch/dries/RPMS/
enabled=0

2: Download the GPG key, install it and then remove the local copy (once it’s imported, you don’t need the key file any longer)

wget http://dries.studentenweb.org/rpm/RPM-GPG-KEY.dries.txt

su -c 'rpm --import RPM-GPG-KEY.dries.txt'

rm RPM-GPG-KEY.dries.txt

Done, now you can install the programs via yum. The Dries repo isn’t enabled by default (I only leave official yum repos enabled on my machine). The command below will enable the repo for this install only. If you want to enable dries full-time, edit the dries.repo file and change enabled=0 to enabled=1.

su -c 'yum --enablerepo=dries install nload bwm-ng'

Newbie I/O Redirection

Saturday, December 9th, 2006

I’ve been playing around with redirection for the LBO course I’m following. I find what you can do with redirection fascinating (could be that I’m just easily amused). This is all command line work, so if you’re interested in honing your CLI-fu, read on. Some of this is really basic, some of it not so much.

NOTE: All of these commands should be executed with your regular user account. Don’t prefix the commands with sudo, don’t be operating as root.

First things first, you need to know a little about standard input, output and error. Standard input is usually your keyboard, standard out and standard error are usually your screen (or some window on your screen). Each of these 3 types of I/O (input/output) streams have an identifier associated with them called a file descriptor. In short, the file descriptor is an positive integer used to reference I/O.

* Standard input: 0
* Standard output: 1
* Standard error: 2

Before reading on, perform a man ls, man cat & man less to familiarize yourself with the commands we’ll be using.

A simple form of redirection can be illustrated with ls > dirlist. The greater than operator (>) redirects the results of ls to the file dirlist. If the file doesn’t exist when you execute the command, it will be created. If it does exist, it will be overwritten with the output from ls. After executing the command you can use cat dirlist |less to page through the contents of the file in your terminal. The cat command we issued to view the file uses another type of redirection that will be explained shortly.

In this example, you can append output to existing files with a double greater than (>>). If you want to keep a copy of your directory list with the time and date it was created appended to the bottom of the file you could execute date >> dirlist. Perform a cat dirlist to view the changes to the file.

In summary, using greater than (and double greater than), we’ve redirected standard output to a file instead of your screen. With the cat command we’ve redirected standard output from your screen to the input of another program (explained in the next section).

Before reading on, perform a man tee to familiarize yourself with the command we’ll be using.

You can also redirect the output from one program to the input of another. If you wanted to see the output of ls on screen as well as have it written to a file you could enter ls |tee dirlist. The vertical bar (referred to as pipe) character hands the output of ls to the program tee which writes its output to standard output (your screen) as well as a file.

The cat command back in step one worked the same way, the output from cat became the input for less and good ole’ less just spit its results to standard output and you got to read the file in pages.

So, it’s pretty simple to write output to files (> & >>), and it’s equally as simple to send output to other programs as input (|).

Here’s where the fun begins folks :)

Standard out and standard error are normally written to your screen, you would find any errors lines mixed in with non-error lines (this will be clear in a moment). We have the option of directing one or both streams to different locations. This is useful when performing a command that has gobs of results and we want to carefully review them. This is where the file descriptors for output and error come into play.

ls -R /etc/ 1> ~/goodnews 2> ~/badnews

This command performs a recursive directory listing of /etc redirecting the results of standard output (1>) to a file in your home directory named goodnews as well as redirecting standard error (2>) to a file named badnews. This command should return a few errors because of file permissions so execute the command and review the results. Pretty handy eh’?

Here’s my FAVORITE new toy. Not only can we send the results to files, but we can redirect output to other terminal sessions. Just for the joy of it, start 3 terminal sessions and arrange them so you can see them all at once. In each terminal, you will need to enter the command tty. The output will give you the device number of the current PTS (pts is a psuedo terminal). The results will look something like /dev/pts/x where x is a number. I’ll be using /dev/pts/8, 9 and 10.

In terminal that returned /dev/pts/8 I enter:

ls -R /etc/ 1> /dev/pts/9 2> /dev/pts/10

All of the non-error messages (standard output) are sent to /dev/pts/9 and all of the errors (standard error) are sent to /dev/pts/10. You can’t tell me that isn’t the coolest thing :) .

These are just a few examples of redirection, there’s a lot more that you can do with it. Chapter 5 of the LBook on http://linuxbasics.org will give you more information and a series of useful exercises following the reading.

Data rescue, thank you Knoppix!

Wednesday, December 6th, 2006

I just wanted to thank the Knoppix project for making it soooo damn easy to save files from a Windows machine that simply refuses to boot.

Over the weekend my wife brought me a co-workers XP Home machine that would freeze following POST, you know, right about the time the system attempted to boot.. I planned on wiping the machine and using it’s recovery partition to restore the OS, and that’s what I did. Just before reloading the box, I burned a copy of the Knoppix 5.01 DVD, booted into the live KDE interface, mounted a samba share served by my Ubuntu desktop, and copied everything from the user’s profile on the broken box to my system. It was a breeze and took no time at all.

I’ve fixed similar problems in the past but it usually required physically moving the hard disk to a working system, copying the data off, moving the disk back, reloading it and then copying the user’s data back. I found that method to be preferable to mucking about with XP rescue, which I found to be hit or miss.

This is one of many reasons I’m loving the Linux experience. Knowing how to use a tool like Knoppix makes fixing things for others a pleasure instead of an annoyance. Looking back, the first time I tried Knoppix I couldn’t do much more than stare at it. Now, it just feels right. I can start it up, do what I need to and move on. The last few months have been a terrific learning experience.

For anyone interested in the commands I used to mount the samba share, I opened a terminal session on the Knoppix/Windows box and did the following:

mkdir Desktop/ubuntu

sudo mount -t cifs //192.168.1.99/download Desktop/ubuntu -o user=matt

The first command created an “ubuntu” folder on my Knoppix desktop. The second mounted the “download” share from my Ubuntu machine (which has the IP address of 192.168.1.99) to the folder created in step one. The options at the end of the second command just specified that I wanted to connect as user “matt”. After entering my password I was ready to start dragging directories and files from the broken machine to the ~/Desktop/ubuntu mount.

I could have gone an even easier route, just opening konqueror and browsing to the share would have gotten me the same results. I prefer mounting via the command line, I want to have the options burned to into my memory so I can do it whether the box runs a GUI or not.

Ubuntu Edgy: Failed to Initialize HAL!

Sunday, December 3rd, 2006

Grumble! For whatever reason, I started receiving a “Failed to Initialize HAL!” error whenever I started my notebook and launched Gnome. The result was that powersaving features were disabled. There may have been other issues but I didn’t have time to explore. This machine is primarily used by the Mrs. and her user experience with the computers in this house needs to be perfect, that’s a hangup of mine, she’s actually pretty relaxed when it comes to the machines. As long as they work when she needs them she’s cool.

The good news is that there’s an easy fix for it. https://launchpad.net/distros/ubuntu/+source/dbus/+bug/19577 gives you all that you need to get fixed up. However this shouldn’t really be a problem.. It seems that this fix was for Breezy and it shouldn’t have been a problem in Edgy. *shrugs*

Anyway, to fix this problem, enter the commands below. After that, all should be fine. Oh, I just rebooted after entering the commands, you may not need to do that.

sudo update-rc.d -f dbus remove

sudo update-rc.d dbus defaults 12