Posts Tagged ‘Linux’

Jolicloud is of the Awesome

Thursday, July 22nd, 2010

So if you haven’t heard of Jolicloud http://www.jolicloud.com/, then you need to download and install it now. It’s an Ubuntu based OS (a self-proclaimed “Cloud OS”) specifically designed for Netbooks, and it rocks. I have Jolicloud installed on my Samsung N110 Netbook, and I use it for everything from e-mail to games (snes9x) to work (Perl/Vim/Screen). Now what makes Jolicloud super-awesome is that it treats web applications no differently from desktop applications. Each application gets it’s own icon on the “Home screen”. It’s also socially aware - it can connect to facebook and allow you to search for applications and/or people who’ve used those applications, so that you can ask them questions and get guidance on the tools you’re trying to use.

The interface is very slick - big icons and a clean method of navigation to the lesser used functions of a standard Gnome/Ubuntu desktop. The most-awesomest part is that once you load up a terminal, you have full access to the command-line and all Ubuntu apt repositories.

Jolicloud isn’t just for netbooks! I’ve also installed it on my Acer Veriton (similar to the Acer Revo), and am using it as a media center OS. Jolicloud also comes in an “express” edition, which allows you to install it under windows, where it will come up as a secondary OS option under the windows boot-loader.

If you have a netbook, nettop, or any light-weight PC, then install Jolicloud. Highly recommended.

Using DZEN with Xmonad to view Currently Active Network Shares

Wednesday, January 27th, 2010

Currently Xmonad is my window manager of choice, because it’s clean, functional, and removes all the unnecessary crap that most modern desktops usually come with by default.

Although Xmonad is very cool, there are still some things that it’s lacking as far as functionality. Much of this is made up for by the use of Xmobar, Trayer, and other Xmonad compatible plugins and applications. I recently came across another one of these applications, and found it to be an exciting find. The tool is called Dzen.

Dzen is a desktop messaging tool which allows you to easily write some useful scripts, and have the output of those scripts become part of your desktop interface. Many examples of how this works are available on the Dzen webite, but some examples are as follows:

  • CPU Monitoring graphs
  • dmesg log monitoring
  • Notification of system events which are commonly found in syslog
  • E-mail or twitter alerts shown on your desktop as they come in
  • Custom calendar alerts
  • and much more..

Now this idea is not new - I remember there being a project called “OSD” (on-screen display) which essentially allows you to do the same thing. However, I think OSD was meant as more of an single message notification system, rather than the way that Dzen works, with master and slave windows, and the ability to implement menus, etc.

In any case, I decided to give Dzen a try, and am happy with the tool that I’ve been able to whip up. For the longest while, I wanted the ability for my xmonad environment to tell me, at a quick glance, what network mounts and removable devices I currently have mounted. I’m sure that this kind of information is easily available on many bloated desktops, including GNOME and KDE, but I was looking for something simple, small and configurable. Didn’t find it, so I ended up writing my own - with the help of Dzen.

Here are a couple of screenshots of how it looks:

Dzen “Active Mounts” widget (mouse out):
dzen-1

 

Dzen “Active Mounts” widget (mouse over):
dzen-2

 

I wrote the scripts fairly quickly, so I’m sure they could be written better, but I think they will provide those of you who are interested, a good example of how to implement a regularly updated notification widget with Dzen.

The scripts are written to check for changes in the mount list, and only update Dzen when a change is detected. It is written in two components:

1) A perl script which captures the mount information in the exact format that I want, and
2) a bash script which handles loading Dzen

Here’s the source code (perl script):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
 
# Written by J. Bobby Lopez <jbl@jbldata.com> - 27 Jan 2010
# Script to -be loaded- by the 'dzen-mounts.bash' script
# This script can also be run by itself, if you want to dump a
# custom plain-text table of your network shares or removable
# devices.
#
# This script is meant to be utilized the Dzen notification system
# Information on Dzen can be found at http://dzen.geekmode.org/
 
use strict;
use warnings;
 
use Data::Dumper;
use Text::Table;
 
my @types = qw( cifs ntfs davfs sshfs smbfs vfat );
 
sub getmounts
{
    my @valid_mounts; # to hold mounts we want
    my @all_mounts = split (/\n/, `mount`);
    foreach my $mount (@all_mounts)
    {
        foreach my $type (@types)
        {
            if ( $mount =~ m/$type/ )
            {
                push (@valid_mounts, $mount);
            }
        }
    }
    return @valid_mounts;
}
 
sub getsizes
{
    my @mounts = getmounts();
    my @list;
    foreach my $mount (@mounts)
    {
        my @cols = split (/\ /, $mount);
        my @df_out = split (/\n/, `df -h $cols[2]`);
        $df_out[1] .= $df_out[2] if defined($df_out[2]);
        $df_out[1] =~ s/[[:space:]]+/\ /;
	    my @df_cols = split (/[[:space:]]+/, $df_out[1]);
        push (@list, ([@df_cols]));
    }
    return @list;
}
 
my $tb = Text::Table->new(
	"Filesystem", "Size", "Used", "Avail", "Use%", "Mounted on"
);
$tb->load(getsizes());
print "Active Mounts\n";
print $tb;

And the bash script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
 
# Script to load Dzen with output from 'dzen-mounts.pl' script
# Written by J. Bobby Lopez <jbl@jbldata.com> - 27 Jan 2010
#
# This script utilizes the Dzen notification system
# Information on Dzen can be found at http://dzen.geekmode.org/
 
function mountlines
{
        LINES=`perl dzen-mounts.pl|wc -l`;
        echo "$LINES"
}
 
function freshmounts
{
        OUTPUT=`perl dzen-mounts.pl`;
        echo "$OUTPUT"
}
 
function rundzen
{
        OUTPUT=`freshmounts`;
        MOUNTLINES=`mountlines`;
        echo "$OUTPUT" | dzen2 -p -l "$MOUNTLINES" -u -x 500 -y 0 -w 600 -h 12 -tw 120 -ta l &
        PID=`pgrep -f "dzen2 -p -l $MOUNTLINES -u -x 500 -y 0 -w 600 -h 12 -tw 120 -ta l"`;
        echo "$PID"
}
 
function killdzen
{
        PID="$1"
        if [ ! "$PID" ]; then
            MOUNTLINES=`mountlines`;
            PID=`pgrep -f "dzen2 -p -l $MOUNTLINES -u -x 500 -y 0 -w 600 -h 12 -tw 120 -ta l"`;
        fi
 
        if [ "$PID" ]; then
            #echo "Killing $PID..";  # DEBUG STATEMENT
            kill "$PID";
        fi;
}
 
function checkchanges
{
    while true; do
        NEW=`freshmounts`;
        #echo "$NEW - new";  # DEBUG STATEMENT
        if [ "$OLD" != "$NEW" ]; then
            killdzen "$PID";
            rundzen;
            #echo "$PID started";  # DEBUG STATEMENT
            OLD="$NEW";
            #echo "$OLD - old updated"  # DEBUG STATEMENT
        fi
        sleep 1;
    done
}
 
checkchanges

You can also download the scripts in a tgz archive here. Enjoy!

Back to Basics - Very Simple Log Monitoring with Perl

Friday, March 6th, 2009

There are many many tools out there which allow you to monitor and view your system or networking logs in several different ways.  Sometimes though, you may find yourself looking for a specific feature that none of these tools currently provide.  Whenever your goals are very specific, and you don’t want to use a big feature-full program to accomplish a simple task, you may want to consider writing your own tool.

Below is a simple Perl program I wrote which does just that. All the requirements of the program are within the script itself (using the __DATA__ handle at the bottom of the file). The only thing you may need to install on your system to get this to work is the File::Tail CPAN package.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w
 
use strict;
use File::Tail;
 
my @patterns = <data>;
my $file = File::Tail->new ("/var/log/syslog");
while ( defined(my $line=$file->read) )
{
    my $match = &filter($line);
    if ( $match eq "no" )
    {
        print $line;
    }
}
 
sub filter ()
{
    my $line = $_[0];
    my $match = "no";
    foreach my $test (@patterns)
    {
        chomp($test);
        if ( $line =~ m/$test/ )
        {
            $match = "yes";
        }
    }
    return $match;
}
 
__DATA__
PROTO=UDP SPT=67 DPT=68
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.111.*PROTO=TCP.*DPT=80
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.102.*PROTO=TCP.*DPT=80
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.111.*PROTO=TCP.*DPT=443
ACCEPT IN=br0 OUT=vlan1 src=192.168.0.102.*PROTO=TCP.*DPT=443
ACCEPT IN=vlan1 OUT=br0.*DST=192.168.0.101.*PROTO=UDP.*DPT=1755
ACCEPT IN=vlan1 OUT=br0.*DST=192.168.0.101.*PROTO=TCP.*DPT=1755
ACCEPT IN=br0 OUT=vlan1 src=10.100.0.1.*PROTO=UDP.*DPT=53
JBLLNXWKS dhclient
 
__END__

This program will monitor the end of the file (like the Unix ‘tail’ command) and check for new log entries. When it detects new lines in the log, it will filter those lines with the patterns defined at the end of the script (under __DATA__) and display anything it detects in the logs except those filter lines.

You’ll probably notice that the filter lines are regular expressions, which makes this script more powerful than doing filtering by simple full-string comparison.

Aside from simply printing the output to STDOUT, you could use regular expressions to pop pieces of each line into an array or hash, in order to do calculations, such as how many entries had a source IP of X, or destination port of Y, etc.

Its definitely a good thing to keep in mind that whatever software you could possibly need is already out there on the internet, and possibly open source. However, its also good to keep in mind that YOU can create a tool yourself to accomplish your specific task; all it takes is a little self-confidence, effort, and patience.

Configuring X.Org Display Resolutions Under Ubuntu 8.04

Sunday, February 15th, 2009

Problems with High Resolution Monitors and X.Org

I recently bought a 28′ LCD Monitor, the I-INC iF281D. I bought the monitor to increase my usable desktop workspace on my Ubuntu 8.04 (Hardy) Linux workstation. I do a lot of programming, systems administration, log analysis and monitoring - and I usually have three or more X Terminals open at any one time (with some mixture of “top”, “vim”, “tail”, and “screen” open), so the more desktop space I have, the better.

When I first attempted to configure my new monitor using the ‘nvidia-settings’ GUI application that comes with NVIDIA’s Linux driver, I noticed that it didn’t present all the resolutions that the monitor supported.  NVIDIA’s Settings GUI was limiting the available resolutions to a maximum of 1280×800. This was odd, because the monitor supported resolutions up to 1920×1200, and supported DCC, so the GUI should have been able to pick up the monitor specifications and provide configuration options for all supported features (resolutions, refresh rates, etc.)

At first I thought that the problem was with the NVIDIA driver I was using, and so I downloaded the latest driver from NVIDIA’s website, recompiled and tried again.  I still however was not able to get the resolutions that the monitor supported.


My 28 Inch Desktop @ 1920x1200

Solving The Problem

After much more digging and research, I found that the problem was not with the monitor, or the NVIDIA driver, but with the mode settings in ‘xorg.conf’. What I wasn’t aware of was that the Horizontal Sync rate definition within my ‘xorg.conf’ directly reflects the resolutions that will be available to me.

For example, the ‘nvidia-settings’ application set the Horizontal Sync and Vertical Refresh to low (safe) values by default. Therefore the available resolutions were limited. Once I figured out what my maximum HZ Sync and VT Refresh were, I was able to achieve the resolutions that the monitor was capable of.

There are Xfree86 Video Timing HOWTO’s available if you want to get into the gory details of how to calculate the correct xorg.conf settings for your specific monitor. However, if you’re a programmer like me, then you’ll want to skip this step, expecting that someone else out there must have already been through this, and has likely created a tool to make our lives easier.

Lo and behold! Xtiming is a great web tool which helps you calculate your Horizontal Sync and Vertical Refresh Rate settings. Simply enter the resolution that you are trying to achieve, and Xtiming will tell you the settings you’ll need in your ‘xorg.conf’ file to get it.

For example, if you leave empty all the other values that Xtiming asks you for, and simply enter “1600×1200″ for Visible Resolution, and “60″ for Refresh Rate, then click “Calculate Modeline”; you’ll see that Xtiming returns the Mode Line that you should use, along with (and most importantly!) the Horizontal Sync rate you will need to achieve that resolution at the specified refresh rate:

1
2
Modeline "1600x1200@60" 176.70 1600 1632 2296 2328 1200 1224 1236 1261
Horizontal sync frequency: 75.9 kHz

I personally found that I didn’t need to use the “Modeline”, but the Horizontal Sync Frequency was essential. Here’s an excerpt of my ‘xorg.conf’ file using the above settings:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(...)
 
Section "Monitor"
 
    # HorizSync source: xconfig, VertRefresh source: xconfig
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "AUO"
    HorizSync       30.0 - 75.9
    VertRefresh     60.0
    Option         "DPMS"
EndSection
 
(...)
 
Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "TwinViewXineramaInfoOrder" "DFP-0"
    Option         "TwinView" "1"
    Option         "metamodes" "DFP-0: 1440x900 +1600+0, DFP-1: nvidia-auto-select +0+0"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

I’m using TwinView because I have a dual monitor setup. However, now that I have a 28′ display, dual displays don’t really seem to be a requirement any more :)

Setting Up SSH Keys

Wednesday, September 3rd, 2008

Here is my attempt at a very quick and dirty guide to setting up SSH Keys using OpenSSH. If you are looking for a way to securely login to one or more boxes, without being prompted for your password every time, then using SSH Keys is probably your best bet.

Here we go..

Using SSH keys allows you to SSH from one host to another in a more secure manner, or (optionally) without the need for a password.

Lets name our example hosts:

  • local host is called my_pc
  • remote host is called devhost



On my_pc (the host you are SSH’ing from):

ssh-keygen -t dsa

This will generate two files (a key pair), for example:

id_dsa - this is your private key
id_dsa.pub - this is your public key

ssh-keygen will ask you for a password/pass-phrase. At this point, you can enter a pass-phrase, or just hit [enter] to use a blank password.

  • Note: if you are creating a key for a user account, you should always use a pass-phrase! Only consider omitting pass-phrases when the key is being used for one-off automated system to system transactions.

If you haven’t done so already, give your private key a descriptive name, like my_pc.id_dsa.

If it doesn’t exist, create the file ‘~/.ssh/config‘, with the following contents:

Host devhostIdentityFile ~/.ssh/my_pc.id_dsa

Note that the ‘config‘ file can be configured with multiple private keys. Make sure that devhost is resolvable by hostname, or this will not work.

(Note: I’ve had some trouble using IP’s in the ‘config‘ file)

Make sure that ‘my_pc.id_dsa‘ is only readable/writeable by it’s owner. Make sure that ‘config‘ is only writable by it’s owner.



On devhost (The host you are SSH’ing to):
Copy the public key from my_pc to devhost, and append it’s contents to the end of the ‘authorized_keys2‘ file, like so:

cat id_dsa.pub >> ~/.ssh/authorized_keys2

Note that the ‘authorized_keys2‘ file can hold multiple public keys.Make sure that ‘authorized_keys2‘ is only readable/writeable by it’s owner.You’re Finished! You should now be able to SSH from my_pc to devhost using SSH keys, and without the need for a password if you so desired.



Troubleshooting:
Use ’ssh -v’ to enable verbose debugging when testing SSH connectivity.This was tested with OpenSSH on Ubuntu 8.04 LTS, and I’ve used this same method successfully on previous versions of OpenSSH, and on other Debian-based operating systems. Your mileage may vary depending on your OS and version of OpenSSH.

Mindnet.Ca Now Running Ubuntu Linux

Wednesday, April 27th, 2005

After a long run of having the Mindnet.Ca server running off a Knoppix Live CD, I figured it was time to pull everything together and put www.mindnet.ca, the Mindnet CVS, and The Bag Of Holding (TBOH) all on a properly installed and configured server. After careful consideration with regards to security, performance, and especially stability, I’ve decided to have the server run on Ubuntu Linux. Ubuntu is a Debian GNU/Linux based distribution that has a more consistant release cycle. Ubuntu is a fairly fresh (new) distribution, so it’s development model still needs to mature, however the project looks promising.