Tuesday, October 24, 2006

NFS sever on Ubuntu 5.10

To setup nfs server on you Ubuntu, few steps are required.

  1. Install packages sudo apt-get install portmap nfs-common nfs-kernel-server
  2. Create, if not exists, file: /etc/exports where you indicate folders you want to share. For example I have in my exports (IP addresses have been change):
    /home/me/mynfs 196.17.227.221/255.255.255.0(rw,sync,all_squash)
    The above means I want to export the /home/me/mynfs directory to computer 196.17.227.221 with the options "read&write" &"sync"&"all_squash".
  3. Start/restart you nfs server: /etc/init.d/nfs-kernel-server start
That should works. To check if you are really exporting something you can use:

showmount -e localhost

and if you see:

Export list for localhost:
/home/mwolski/mynfs
196.17.227.221/255.255.255.0

it means it work. However, there can be little problem caused by firewall. I had to enable all connection to port 2041, to allow external users to connect to my share. To chack if you can mount this share from other computer, just run showmount -e IP_OF_NFS_server.

To run NFS server it is enought.

Later I will descripe how to mount nfs share and also I try to figure out all those nfs options, you can put to /etc/exports.

Monday, October 23, 2006

Finally my blog is live again

Hi everyone!!
Finally, after few months of absence my blog returns to the Web. Unfortunately, my former blog is down, due to server problem; hence, I decided not to wait longer and to sing up for google blog.

First thing, that I have to do, is to recreate my posts from my former blog. It should not take log. Afterwards, I will put some new content. Hope you will enjoy.

Friday, October 06, 2006

Mac X 10: How to make screenshots

Basically there are to ways of doing screen shots on Mac X:

1. Basic
2. Using Grab program

Basic
To capture entire screen you press Command-Shift-3 and the Picture 1.png image file is created on your desktop. You can also use Command-Shift-4 to select only part of your screen, and just like before Picture.png file will be created. On the other hand using Command-Shift-Control-4 instead of file, the screen is copied to the clipboard.

Using Grab program
This program is in Applications -> Utilities folder.

I personally prefer the Basic way of doing screen shots. For me it is more convenient. Moreover I prefer png files over tiff files, which are created by Grab.

Sunday, September 24, 2006

Perl: File handle as function argument

Recently I was writing one function in Perl. And I come across one little problem - I did not know how to pass and file handler to a function. Nothing big, but it gave me a little of googling to find the answer for this.
So, let me just give a solution to this problem, without any further explenation.

#!/usr/bin/perl
use strict;

open(FH,"> some_file.txt");
print FH "Write first line to the file";

writeToFile(*FH);

sub writeToFile {
my $FH = shift;
print $FH "Write second line to the file";
}

Hence, one must remember that when we past a file handler to a function in Perl, we must do it using '*', no other way that I know of works.

Ruby, is it worth my interest?

Recently, I read about new scripting language from Japan - Ruby. I already know quite good Perl, so I decided to read a little more about this, because what I had read, expressed very good opinion about this new language.

Ruby, as its homepage says, is: "the interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (as in Perl). It is simple, straight-forward, extensible, and portable ... and free of charge".

On the grounds of above, I decided to give it a try.

Installation

I was surprised to find out that my Mac X Tiger has embedded Ruby interpreter. So users using newest Mac's don't have problems with installation. Despite this, i decided to install it on my Ubuntu Breeze, by running sudo apt-get install ruby. As a result, Ruby was installed on my Linux.

My first script

To get an idea about this programming language, I decided to write a little program, that reads two text files containing mainly numerical data, organized into tables (tabulator as separator between columns). Below is an example of file's content:


As can be seen from the table above, it is typical text file with data. I used two such files, but with different numerical data. I wanted to write some script that takes those to files, performs some mathematical operation on numerical data, and gives summary of calculation.

In this moment I'm not going to describe or explain further details attributed to this script, or give any example code. Just want to share my opinion about my first impression of Ruby.

First steps

I must say, that starting to learn Ruby, was quit easy. This is mainly because of book-like tutorials available at Ruby's homepage. I hadn't have any major difficulties in writing my script. However, there was one thing which caused a little of confusion at the start - iterators like in line (2):

myarray = [1,2,3,4] # (1) create array of name
myarray.each { |i| puts i} # (2) for each element in myarray do 'puts i'-print i

But, after a while, you can get used to them, and what's more important, see how useful they are.

There are many more other inventions in Ruby, which I will be describing as time goes.

Conclusion

In conclusion, I must say my program was written relatively fast. I didn't have any bigger problems with it. However, there was huge problem with making intersection of two arrays of objects, but my own solution to this obstacle, I will describe later. Despite this I must definitively say that I will continue to use Ruby, because it is very clean and easy language.

Mysql, mysqld.sock missing

Lately I find my self in trouble with running mysqld 4 on Ubuntu 5.10. The problem was with missing mysqld.sock. While starting mysql I saw:

/usr/bin/mysqladmin: connect to server at 'localhost' failed error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock (2)' Check that mysql is running and that the socket: //var/run/mysqld/mysqld.sock' exists !

Normally mysqld.sock is created by running mysqld command. Unfortunately, this command gave:

/usr/sbin/mysqld: Cant't open file: 'host:MYI'. (errno: 142) Fatal error: Can't open privilege tables: File = '/usr/share/mysql/charsets/?.conf' not found (Errcode: 2)

First I tried mysqld --default-character-set=latin1 but it did not help. So I finaly executed

myisamchk -dvv host.MYI

and I saw

myisamchk: Character set '#'83' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index' file myisamchk: error: 142 when opening MyISAM-table 'host.MYI'

The solution was to add to file /usr/share/mysql/charsets/Index only one line:

cp1251 83

Sunday, September 10, 2006

Perl: Creating empty arrays and hashes

Using arrays and hashes in Perl is essential. Nevertheless Perl way of handling those data types is more difficult; by comparison with, for example Ruby or Python. Now I am not going to focus on all aspects of arrays and hashes in Perl, because this topic is just to big for one post. Today, I will describe funny problem that my co-worker had, or rather his little bug in his program.

The problem was with deleting or emptying and array or hash.
For example, let assume that we have one array @a, and one hash %h:

my @a = ( 2, 3, 4);
my %h = ('me'=>2, 'you'=>3, 'he',=>'4');

print 'Size of @a: ', scalar @a; #gives 3
print 'Size of %h: ', scalar keys %h; #gives 3


Now, we want to delete its content. What my friend did, was:


@a=[]; #WRONG: should be @a=();
%h={}; #WRONG: should be %h=();

print 'Size of @a: ', scalar @a; #gives 1 !!!
print 'Size of %h: ', scalar keys %h; #gives 1 !!!


This little mistake cost him a lot of hours of looking for bug in his code. What he did, he created anonymous empty array [] and anonymous empty hash {} and assign them as first element in $a[0] and as first key in %b.

Hence, the correct code to empty an array or a hash is:


@a=();
%h=();

print 'Size of @a: ', scalar @a; #gives 0 !!!
print 'Size of %h: ', scalar keys %h; #gives 0 !!!

Thursday, August 24, 2006

Matlab and Perl: returning matrixes and cells from Perl to Matlab

Matlab, as one of the most preferable hight level languages among the scientist all over the world, provides interfaces to other programming languages. Normally you can attach to Matlab scripts programs written in: ANSI C, Java SDK , Fortran. This process is called external interfaces and information about it can be found here.

In addition to those languages, there is also possibility to use Perl programs within Matlab scripts. This can attributed to the fact, that Matlab, by default, has embedded Perl interpreter (in fact, it's tripped-down version of the interpreter). Therefor, you can use Perl scripts without any problems.

However, in contrast to ANSI C, Java SDK , Fortran interfaces, Matlab doesn't have any build in routines, to pass and return matrices, cells, vectors to and from Perl. The only thing returned to Matlab is string, which represents stdout of Perl script, meaning, that Matlab receives everything what is returned by print functions in Perl. Everything which normally is printed on stdout, is assigned to one string variable in Matlab. For instance if myscriptInPerl.pl is simple perl script print to console something, then executing this in Matlab console:

A = perl('myscriptInPerl.pl', var1,' var2', var3);

assigns to variable A, all output of myscriptInPerl.pl.

Based on that, my own solution to get matrices, cells, vectors, etc. returned from Perl, is to return string, representing Matlab's code, and executing function eval(A) in Matlab. For example

#myperlscript.pl
#Example file, with Perl scribt to be executed by Patlab
#

$out = "myVector = [2 3 4 5 5 6]; "
#variable with string representing Matlab vector

print $out; #print $out to Matlab

Executing above script in Matlab and evaluating returned string will create myVector variable in Matlab:

A = perl('myscriptInPerl.pl', var1,' var2', var3);
eval(A);

myVector =

2 3 4 5 5 6

Installation of Kubuntu 6.06

Few days ago I was helpping one friend with installation of Kubuntu 6.06 on a PC. I have to admin that personally I would prefer ubuntu, rather then Kubuntu, but he is a fan of KDE environment, so we downloaded it.

I haven't seen Ubuntu yet, so Kubuntu is my first insight into Dapper Drake (DD) family, which has drawn a lot of public attention lately, as being first distribution from Canonical with three and five year support, for desktop and server usage respectively. Since the release, I have read plenty of reviews and opinions about both Ubuntu and Kubuntu. Majority of them was positive about them, and many authors have stayed that (K)Ubuntu is definitively going in the right direction. Due to the fact there is huge amount of available reviews I'm not intending to write one more. Instead, I just want to describe my own experience and feeling about Kubuntu.

To begin with, I need to write that everything went smoothly, and there was not any single problem with installation, even though this PC was more then seven years old.

First positive aspect of Dapper Drake that I noticed is, that the CD you download, both Live and installation CD. Owning to this I could first check if Kubuntu would be working on my PC. I other world's, I could check if Internet connection, printer, etc. was OK. Afterward, knowing that my hardware worked, I started the installation.

Process of installation went smoothly, within surprisingly short time.

After that, I needed to install some additional stuff to my new operating system, so my first thought was to start Synaptic. And I was quite surprised, to find out that there was no Synaptic (graphical package management program for apt). So, no problem, I just run: sudo apt-get install synaptic and there was another surprise - nothing happened. So still, no problem, I open /etc/apt/sources.list and i had to manually unhashed few repositories. Finally, following all those operation I maneged to install what I wanted. Nevertheless, I had and still have mixed feelings about this.

As most of the users I (my friend) wanted to have mp3 support, video codecs, and other popular things, which desktop user must have, and they are not included in (K)Ubuntu by default, on account of licents difficulties. Because of that, I used easyubuntu. This is Python "script that gives the Ubuntu user the most commonly requested apps, codecs, and tweaks that are not found in the base distribution". It worked perfectly, in few minutes I had everything I wanted, and everything was working (audio/video).

Next, I needed to setup printer. I use netwerk HP printer. And there was no surprise, niether. It just worked, after finding it on the list of all printers in configuration panel.

The last stage, was to install VMware server. Unfortunately, this must be done manually, because there are no apt packages. So, I registered (to download vmware you must to register in order to receive free serial number) and I began the installation. There was another nice surprise, everything went perfectly. All process of vmware setup, consists of accepting default parameters :-). That was it:-)

So in conclusion, I strongly feel that Dapper Drake is good or even very good distribution, if you consider only first impression only. However, that little difficulty with Synaptec and apt, can be problem for newbies. I am sure, that my sister, would have huge problems with that, and what's more, I don't see any reasons why it is done like this.

This was my first text about Kubuntu 6.06. I reckon that during further exploitation there will be something new and maybe more interesting to write about.

Gmail and importing mails from other mail account

Some time ago, I switched from my old webmail, to new gmail provided by google.com.

Everything would be perfect if not the fact that gmail, does not have option for importing e-mails form other pop3 servers.

The only solution I found was to download all you emails using e.g. MS Outlook or Evolution. After this, it is necessary to run special program, which will send all your just downloaded mails to gmail account. It isn't the best solution to this problem, but I could not find enythig else.

Fortunetlly, I have access to Linux server with reasonable bandwich, so I downloaded all my mails from former account (more than 600MB) using Evolution mail client. It is client which goes with Gnome as default. Following this, you need to use one of available programs (gExodus - only Windows, gml, ngml) to export you mails from e.g. Evolution to gmail account. Evolution stores all emails in mbox files. If you use Ubuntu Breeze 5.10, this file shoud be somewhere in you home directory.

To export all you emails stored in mbox you can use e.g. gml python script. However, this script wasn't working for me. So, I found modyfied gml (ngml).

Example usage of ngml:

ngml mbox "/home/me/.mail/Inbox/Inbox.mbox" myaccount@gmail.com

And, finally it worked. All those operation were performed on Ubuntu server, which was used, in this case as SMTP server to send all those emails.

Nevertheless, I found it very strange that you have to do so many tricks to import your mails to gmail account. I wander why it is so complicated?