Saturday, March 31, 2007

Finding the time...

After discovering that the clocks on several of the servers I work with now were out of sync, I decided to check my own system's accuracy. The simple command "ntpdate [server]" (on Ubuntu by default) will sync your clock with whatever server you select. "ntp.ubuntu.com" or any of the North American NTP pool servers (e.g., 0.north-america.pool.ntp.org) will work fine.

However, before you think of the clever idea of adding this command to a cron job or startup script, know that there is a better way: ntpd. This is a daemon that is designed to bring your clock in sync with time from the atomic clock time servers optimally. It adjusts the time to a synchronized state in small increments so as not to harm programs that rely on a regular passage of time, and so that your logs don't appear to jump. It works very well, and keeps your clock as accurate as possible all the time.

One catch: ntpd is not installed on Ubuntu by default, as they did not want any network listening apps installed on the desktop version by default. And good for them to improve security. The problem is that ntpd will not be found in the repos. It goes under the guises "ntp-simple" and "ntp-refclock". The latter is really only when you want to set up your own time server, and have the means to do so. The former is what should be used to keep "simple" (single, personal) systems synced. So install that.

There are a few more steps left. Run ntpdate to get the current time:
sudo ntpdate ntp.ubuntu.com

Then edit /etc/ntp.conf:
sudo vim /etc/ntp.conf

Add the lines after these 2 (should be there already):
# You do need to talk to an NTP server or two (or three).
server ntp.ubuntu.com
server 0.north-america.pool.ntp.org
server 1.north-america.pool.ntp.org
server 2.north-america.pool.ntp.org
server 3.north-america.pool.ntp.org

Lastly start up the ntp server:
sudo /etc/init.d/ntp-server start


To see the results:
sudo ntpd -p

Friday, March 30, 2007

Neat Firefox Shortcut and More Handy Display Config Candy

I accidentally discovered an awesome shortcut in Firefox today. I wanted to switch to a workspace in fluxbox, but my sausage finger excuses for fingers pressed Alt+4, not F4, of their own volition. Serendipitously, Firefox had focus at the moment, and I was surprised to see my current tab switch... With confusion and adumbrated glee, I tried my mistake again. It turns out that Alt+NUMBER switches to that tab in the current Firefox window, handily similar to workspace switching. It is a great shortcut.

On an unrelated note, I was still having problems getting my fonts to look how I wanted in fluxbox. A friend directed me to try running "gnome-settings-daemon" (add "gnome-settings-daemon &" somewhere in .fluxbox/startup) at boot. Upon doing this, my fonts automagically looked as they should. I don't know what it does exactly, but run it.

Linux Display Config... Can be Simple!

On rare occasions, one encounters a tool or application which makes blithely simple a task which was once annoying/hard/cumbersome/painful. Such a thing have I seen today: nvidia-settings. It has long been the case that having an NVIDIA graphics card has made using a GUI much simpler in Linux (although support from other vendors has been increasing). However, trying something as crazy and far-fetched as... dual monitors... has been somewhat of a dreadful task, involving much editing of xorg.conf, tears on the keyboard when startx reveals another error, et cetera ad nauseum. No, I don't want to see detailed output. I want a simple feature of having 2 monitors to work.

NO MORE! Simply type "sudo nvidia-settings" (in some window manager of course, gnome, kde, etc. Or fluxbox, if you are that cool), and a pretty little interface comes up, where you can do all the obscenely obvious things that one would want to do in configuring a graphical interface, like set up 2 monitors, configure refresh rate, and much much more.

It's amazing. In a few clicks, saving to my xorg file, and a restart of X, I had everything configured how I wanted it. No pain. No errors.

Dude, is Linux made of leprechauns? Cause it is awesome!

Saturday, March 17, 2007

The Sound of Linux

Recently, I came across some rather neat, if obscenely geeky, things to do with sound in linux. Actually, the first can be EXTREMELY useful. Often, using new systems, I do something that results in the PC speaker squawking. If it is trying to use tab-complete in a dir with too many matches available, or a bad VIM command, that tiny speaker decides to notify me of the error of my ways. After this happens one or two times, I am sorely tempted to put my fist through the computer, just to stop that wretched sound. There is a better way, viz., "modprobe -r pcspkr". This effectively kills the PC speaker, for your current session. No more squawking, no more pain. Once you logout, the speaker works fine, it just temporarily saves you the annoyance.

Another thing I have been experimenting with is much cooler. Apparently, you can take any file and send it to your speaker. To try this, get into the CLI, and first do "wget www.cnn.com". Then do "cat index.html > /dev/dsp". Of course, you can dispense with downloading cnn.com's homepage and use any file you want, of any type. Even "ls /etc > /dev/dsp" will do. As long as your sound is enabled, you will get some static. I believe what is actually happening is that you are sending the binary content of whatever you pass to your sound card, and it is playing through the speaker. Images, I find, are particularly interesting. An amusing experiment I have not finished: Make a recording, hopefully a comical one, encode it, and turn its binary content into some text. Embed this in a hidden div in a web page, and get someone to try the above commands on the page. I don't know anything about encoding, or much of anything at this level, but it is fun to play with.

Eterm Oddity

While configuring my Fluxbox setup, I decided I wanted transparent terminals tailing various logs, or running top, from startup. I described getting most of this setup in a previous post. Since then, I ran into and solved two additional problems. The first is a result of specifying the positioning and size of the eterm windows via their title bar, using "Remember", which writes to .fluxbox/apps. Doing this for a transparent window can cause a black bar to appear at the bottom of said window. This is because of the second issue I ran into. When specifying the geometry of eterm through the command line option "-g", the format is "-g NUMOFCOLUMNSxNUMOFROWS+XOffset+YOffset ". The Offset items are in pixels, but the column and row specifications are in, of course, columns and rows, i.e. character widths and rows. So a setting of "-g 80x50+0+500" would make a window holding 80 columns, 50 rows, and it would be placed flush with the left side of the screen, and 500 pixels from the top.

This difference in units is what causes the black bar to appear when using Remember to set eterm's position and dimensions. This is because the Remember setting is in pixels, and a given set of pixel dimensions will not usually correspond to the exact number needed for a whole number of rows. I believe this difference causes the black bar.

Saturday, March 10, 2007

Top to the Top

I have used the top command many times to find out, for example, what errent process was eating up all my memory or CPU. Recently I configured fluxbox to start top in a transparent, borderless, bar-less window at startup, so I could always see what was up, no pun intended.

What I had not done before, however, was read man top. It turns out top is much more than a simple command. There is an entire interactive interface! Just to get a quick idea, type "top" in a terminal. Once it starts, press "f". Up comes a menu to pick which columns you want to see displayed! Just press the letter displayed by each item (its case toggles as you toggle each option), and it will display (or not) once you go back to top (press any non-mapped key, like Tab).

Another neat one: press "o" while top is running. This lets you order the columns that display. I found I liked to have them ordered thus: "Command, PID, S, User, %CPU, %MEM, TIME+". And those are all I really needed, so I disabled the rest. Now top is far less cluttered and much easier to read. Along this same line, press "B" (yes, capital). This bolds important fields and values. It also bolds processes when they are in a Running state, again very useful.

An additional informative note and two warnings: For those woefully uninformed of the coolness of top, it can do quite a bit more than I have mentioned here. You can do a lot with it interactively. But you must be careful as well. Pressing "k", for instance allows you to kill a process after specifying its PID. In addition, after you have configured the columns, order, and anything else to your liking, be sure to press "W". This will write your current setup to ~/.toprc. Otherwise, it's all lost once top is stopped.

For more information on top's abilities in a form shorter than the gargantuan man page for it, see here.

Dockapps for Flux's Slit Reviewed

I have tried out quite a few dockapps over the last week after starting to use fluxbox. I have found some that are helpful, some that are neat, some that are dumb/ugly, and a few that are just plain broken.

To save others the heartache, I shall mention the best in show thus far:
  • wmcube - A neat looking dockapp that shows CPU use as a percentage, as well as via as a randomly selected rotating 3D object. You can change the object by clicking on it. Keeping abreast of CPU usage can now be done from the corner of your eye, since the objects' rotation increases accordingly.
  • wmtop - This shows the 3 items highest on the list provided by top. It can let you know if the app you think should be starting via a keyboard shortcut is taking a long time to start, or isn't starting at all, not to mention if a random thing is hogging your resources. There are 5 different skins for it, so check "wmtop --help" and find one you like.
  • wmusic - This is a tiny remote for the XMMS player. I looked and looked, but basically all of the dockapps for controlling music are for XMMS. This saddened me, until I tried XMMS and got hooked on it as well! It's basically WinAmp, but SO fast. Really. I added 10,000 songs in 2 minutes. They were immediately searchable. It responds immediately to whatever you try do to it. I was amazed, after having tried more music players in linux than I can count with both hands. Aside from these things, there are a ton of skins and plugins for it, greatly expanding functionality, and making it look like whatever you want.
  • wmcalclock - There are a lot of dockapps to show you the time and date, but I liked this the best because of the large, bright, easy-to-read display. Just what you need, nothing else.
  • asmem - The problem I had with the myriad system monitoring applets was that I had to click them to see CPU versus memory usage. I wanted dockapps that were always in a useful state. And I already had 2 neat dockapps for monitoring CPU usage. asmem only monitors memory usage, and it neatly displays RAM and swap use, in MB (configurable) and percentage free (or used). Be sure to pass this "-withdrawn", so that it doesn't have a menu bar and plays nicely with the other slit apps.
  • wmfire - This does the same thing as wmcube, but I like to have them both for eye candy. It shows CPU usage as a fire, increasing in intensity as usage goes up. It's pretty spiffy.
  • wmnet - Providing a quick eye to network activity, this highly configurable dockapp can be quite useful. You can change the refresh rate, all the colors, interfaces, and more. Be sure to pass this "-w" as well, so that it actually fits in the slit.
  • wmwifi - This applet displays what wireless network you are connected to, with scrolling SSID, a bar as well as percentage display of signal strength, and an antennae that indicates connection or lack thereof. A handy thing to have for those that often switch between wireless networks.
  • wmnd - I actually started using this in place of wmnet, since I found it looked much better. It displays the interface being watched, a blinking arrow indicator of upload/download activity, a numeric indicator of data transferred, up and down, as well as a nice graph of activity. It displays much more useful information than wmnet for the real estate used. I found that "wmnd -c red -C blue" works well. You can also lower the -s value to increase scroll rate ( I think 5 is default). Be careful with this. Setting it at 3 made my fluxbox just load the background, and nothing else. After playing with everything in .fluxbox/startup and restarting gdm on the CLI, I found this was the culprit. -c is the download traffic line, -C is for upload.
I thought of something usefully clever to add to wmnet that I have not gotten to work, as a result of my stupidity. You can pass it "-e COMMAND" so that it will launch COMMAND when you click the window. I wanted to view the results of netstat upon clicking it, so that if I saw odd spikes of network activity, I could immediately see the cause. BUT, doing this "-e gnome-terminal -e netstat" will not work. You will get this error: "wmnet: duplicate --execute", since wmnet sees two of the same option.

My proposed solution was to make an alias that I would call "netstat-term", simply being "gnome-terminal -e netstat", so that I could run my wmnet as "wmnet -l -d 60000 -t red -r cyan -e netstat-term", and get what I wanted, while not confusing wmnet. Two problems remain: wmnet does not have access to aliases set in .bashrc, and when I run "gnome-terminal -e netstat", the new terminal opens, runs netstat, and closes. I have tried several ways, but I can't manage to make it stay open as a new process. Hopefully I can solve both soon...

How Flux got his Groove back

One thing you may (or may not) miss upon switching to Fluxbox in Ubuntu is the happy startup jingle. But fear not! You can get it back, via the instructions listed in the Ubuntu guide:

sudo apt-get install sox
gedit ~/.fluxbox/startup
  • Find this line:
exec /usr/local/bin/fluxbox
  • Put this above it somewhere:
play /usr/share/sounds/login.wav > /dev/null 2>&1 &

I did this, exited flux, logged back in, and the happy sound greeted me.

Thursday, March 8, 2007

Transparent Terminals on the Desktop

There are a number of cases in which you might want a terminal window always present on your desktop, perhaps tailing an important log file, or looking at the output of top. Whatever your reason, here are the steps to take if you just want magically dynamic text appear on your desktop.

First, assuming you have Eterm, start up an instance of it and Toggle Transparency in Background. You might also want to play around with the text color, to optimize it for your background. Then add an entry to start it when fluxbox starts in .fluxbox/apps.

Now for the window title bar, button bar, scroll bar, border, and positioning. All of these tweaks can be done via start options. Here's what I have for my Eterm entry in .fluxbox/apps:
[startup] {Eterm -g 60x50+80+5 -O -x --no-cursor -w 0 --scrollbar 0 --buttonbar 0 -e tail -f /var/log/messages}
Going in order: the "-g" options allows you to specify the geometry of the window. You pass it Width x Height + X offset + Y offset. So in my example, I have the window as 60x50, and it appears 80 from the left side of the screen and 5 from the top (this is just past where I have fbpager, which seemed like a convenient place). The -O option takes the background from the root window, assuring transparency. The -x option removes the window's border, -w sets the border width (0 in my case), and the scrollbar and buttonbar as 0 removes those as well.

The -e tells eterm to execute a command. I chose to follow tail /var/log/messages, but you can set it to whatever log file or process you want. Top is a good one to implement like this as well.

So with just that one line addition to .fluxbox/apps, you can have a permanent transparent log output to your desktop. It's useful, and looks awesome.

Wednesday, March 7, 2007

Fluxbox and Thunar

I have switched over to using Fluxbox as my window manager with Thunar as the file manager. After some configuration fiddling, I find it much faster and more efficient than Gnome with Metacity and Nautilus. It runs a LOT faster. A couple things that might throw you off of using it at first: When you first use it after install, it is very plain. It needs help getting dressed. Also, configuration is done through text files. This should not be a problem, but it bothers some people.

Trying it is easy, at least with Ubuntu. Just install it, and log out of Gnome. Then select Options in the lower left, and select session as fluxbox. You can try it out once, or set it as default. There are a lot of tutorials out there on how to configure basic things like the background and menus and shortcuts, and they are mostly very helpful. Not to mention the fluxbox documentation itself, which is great.

Some suggestions:
  • Use Thunar for file management. I find Thunar to be just what I need in all cases thus far, and nothing else. It is fast and efficient. Here are some handy tips for using Thunar.
  • Unless you really want icons on the desktop, Rox can be more trouble than its worth. Case in point: It refuses to be transparent. Say you set a background via fbsetbg, then keep this constant by setting the appropriate rootcommand in ./fluxbox/init. Then you start Rox. Your background turns gunmetal, how peculiar! Of course, you can set a background in Rox, which works fine. Until you want to have an application, e.g. Eterm, be transparent. It will look to the original background, not the Rox one. And there is no way to make Rox itself transparent with respect to background, at least in the current version.
  • Move fluxbox tab placement into the title bar of windows. To me, that wart called a tab on every window got annoying very fast. Positioning them into the title bar means you can still use fluxbox tab functionality, without the wart.
  • The slit is a great thing. You can put lots of handy little dockapps in it to do everything from showing an LCD clock to watching log files. There are a lot in the Ubuntu repos, so run "sudo apt-cache search wm" first. Install what looks good, then add an entry for each in .fluxbox/apps. Restart fluxbox and see what you like. If you decide any of the dockapps aren't you, remove them from the apps file. If you want them in a particular order, you can put them in ./fluxbox/slitlist.
As a side note, it seems that .xpm files need to be used for the icons in the fluxbox menu. I found this out after trying to use .png files, a common format for icons. It's easy enough to convert them: Just open your favorite one per app in the Gimp, Save As, and xpm as the format. Usually, they are stored in /usr/share/pixmaps. Then just update the references to the icons in .fluxbox/menu, and voila, nice icons in your menu.

Tuesday, March 6, 2007

Middle Click to the Rescue!

Yet another extremely simple but well-executed method to increase speed and efficiency present in Linux: Middle mouse button pasting. Open an application, anything with text, a terminal, browser, anything. Select some text. Any text you want. Now go into something else, say a terminal, and press your middle mouse button (or, for the 3 people left without a middle mouse button, press the left and right buttons at the same time (if you have 3 button emulation turned on)).

That's right, your selection just got pasted in. No CTRL+c, no CTRL+v, just select and middle button. Very quick and satisfying.

Some caveats: This only works for text, not for files. So you can't use it in all cases you would use CTRL+c and v, but it is still very useful for text. I find this especially so in a terminal where, if you are using gnome-terminal, for example, you have to copy and paste with Shift+CTRL+c and v. Also, you have to leave the application you selected text in open until you paste. This is because you are not really copying to a clipboard and pasting, but "moving" the selected text.

Friday, March 2, 2007

Fun Times in the CLI

I discovered a few things in the last day that I found to be preponderously fun. Many familiar with the CLI may know them, but I did not, and so I shall share.

The first thing I still don't completely understand, but it works. If you run a script that has lots of requests for input with defaults that you want to accept, there is a better way to run it than "./MYCOOLSCRIPT.sh" and hitting enter a lot. Imagine if it was a script you wanted to run on 20 remote machines to configure something. We need a better way. And it comes in the form of linux's own black hole: /dev/null.

If you redirect from /dev/null to a running script (and to other things, although this is all I have tried), it somehow supplies an equivalent to pressing the Enter key. So you can start the script like "./MYCOOLSCRIPT.sh < /dev/null", and any prompts will be answered with the defaults. I have not been able to get a good explanation of how this works, aside from something about it providing STDIN to the thing it pipes to, but it does work. Beautiful Black Magic.

Another trick is less spine-tingling, but arguably more helpful. Sometimes after typing in a long command, I decide I need to do something else, change the middle of the command, etc. Basically, sometimes I want what I have typed gone, and fast. Usually, I press the Up arrow, hoping to Linus that I entered ls recently, and thus only have to press backspace twice. If I am unlucky, I must resort to holding backspace. Dumb. But, again, there is a better way! Namely, press CTRL+a, then k. You can either hold CTRL+a+k, or hold CTRL+a, release a, and press k with CTRL held. If you release CTRL and a, k will just be entered as a character, so don't do that. Another, shorter, method is CTRL+u. This does the same thing as CTRL+a, k on most systems. I have found that it does not work on certain older distros, so knowing the CTRL+a, k is useful as well. In addition, I found that CTRL+w erases the last word, as defined by a block of characters without a space or tab. This can be helpful if you just botched the last part of a command.

One last mot(e) of coolness. "-A" is a VERY helpful option for grep. If you invoke grep with "-A SOMENUMBER", it will print not only the line matching your text you are grepping for, but also the next SOMENUMBER lines. If there are multiple matches, each match and the specified number of context lines will be separated by a "--" line. I found this so helpful because in a lot of things grep, I don't just want the line the matched string is on, but a little context as well. Options to the rescue.