Determine Solaris OS release

March 30th, 2008

Solaris OS provides the /etc/release file to easily determine the base OS level or the OS release.

cat /etc/release

Solaris 10 8/07 s10x_u4wos_12b X86
Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 16 August 2007

Remote login to a Solaris 10 box

March 12th, 2008

Xnest is a nested X server that I use in some cases to remotely access my Solaris 10 boxes. From Xnest man pages:

Xnest is a client and a server. Xnest is a client of the real server which manages windows and graphics requests on its behalf. Xnest is a server to its own clients. Xnest manages windows and graphics requests on their behalf. To these clients Xnest appears to be a conventional server.

I’ve installed X11 on my MacBook and now I can log into my server:

Xnest -query solaris_host01 :2 &

If you get an error like this:

Not on system console, root login rejected

Edit /etc/default/login and comment out the following line.

# CONSOLE=/dev/console

Be very carefull with this for the security implications. That’s all.

Serial terminal support in GRUB

February 9th, 2008

In some situations it is very useful to have the possibility to access the GRUB boot menu from a serial line. For example you could remotely reboot your machine with the new kernel you just compiled.

In my case I have a couple of remote machines linked together by a serial cable. I can log into machine A via ssh and get the Grub menu of machine B through minicom. Thus I can boot whatever OS/kernel I want as if I were in front of the machine. Kind of KVM IP for the rest of us.

Simply add this to Grub’s menu.lst:

serial –unit=0 –speed=9600 –word=8 –parity=no –stop=1
terminal serial

Debian apt-file

January 27th, 2008

According to man pages:

apt-file is a command line tool for searching packages for the APT packaging system.

So let’s proceed:

apt-get install apt-file

apt-file update

The first command will install apt-file and the second command will fetch the content of the packages from the repositories specified in /etc/apt/sources.list and will resynchronize the contents from the sources.

Now give it a try:

apt-file -v search /usr/sbin/postfix

D: got ‘deb etch main contrib non-free’
D: kept ‘deb etch main contrib non-free’
D: regexp: ^(.*?usr/sbin/postfix[^s]*)s+(S+)s*$
D: Search in /var/cache/apt/apt-file/192.168.1 .2_debian_dists_etch_Contents-i386.gz

postfix: usr/sbin/postfix
postfix-policyd: usr/sbin/postfix-policyd
postfix-policyd: usr/sbin/postfix-policyd-cleanup

Note that you can get similar information by typing this:

dpkg -S /usr/sbin/postfix

postfix: /usr/sbin/postfix

The difference, however, is that apt-file provides information even if the package is not installed or was uninstalled.

MySQL quick backup

January 27th, 2008

This trick will show you how to quickly perform a MySQL backup. So let’s dump all the contents of your databases and compress them to be more portable.

mysqldump -u root -p –all-databases | gzip > myDatabases.sql.gz

If you now want to dump this data to another server, simply type:

gunzip < myDatabases.sql.gz | mysql -u root -p


Mysqldump manual

Sun Microsystems acquires MySQL AB

January 16th, 2008

From Sun Microsystems web site:

Sun announced an agreement to acquire MySQL AB, an open source icon and developer of one of the world’s fastest growing open source databases. This acquisition accelerates Sun’s position in enterprise IT to now include the $15 billion database market and reaffirms Sun’s position as the leading provider of platforms for the Web economy and its role as the largest commercial open source contributor.

More information from Sun Microsystems, Cnet and MySQL web site.

MySQL: quick replacement

December 6th, 2007

Say that you have a table called myTable with several rows and a column called URL that contains the IP address of a log server. Now imagine that you want to change the value of URL so IP address is substituted by the server name. One way to do that is as follows:

use dbname

update myTbl set URL=replace(URL,’′,’logserver’);

OpenSSH: simplifying logins

December 6th, 2007

OpenSSH provides a per-user configuration file usually located in ~/.ssh/config. This file can help ease your life as Sysadmin. Let’s say that you frequently connect to a server in this way:


With OpenSSH there is an easy way to do the job. Edit or create a config file:

vi ~/.ssh/config

and then add the following:

Host servername
     User admin

Where Host is the alias for the remote server you want to connect to, HostName is the full name of the remote server and User is the login name.


KarKomaOnline redesign

December 2nd, 2007

I finally have the time to dedicate in moving KarkomaOnline to the WordPress content manager and made some changes to the look&feel. As always your feedback and posts are very welcome.

Hope you enjoy!

A note for registered users: I’m not going to port the accounts and settings from the old site as this implies a lot of work for me. Please take a minute to register again. Sorry for the inconvenience.

Perl on the command line

May 27th, 2007

Perl, you know perl, is not just a jewel for scripting, it ‘s also a potent onliner.

The magic trick is the diamond:

perl -e ‘while (){print}’ file1

says perl “keep on as long as you read something in the standard in”, in the case of the example above, “print the line” … and each line goes in the memory but not the whole file: you have a powerful stream editor.

The ” -e” switch says to perl that what follows in the command line between the single quotations is a script and not a script file name.

But you can have it quicklier :

perl -ane ‘print’ file1

The switches “-ane” do the “while stuff” for you. It says “do a while () loop” (-n) “and split each record in the @F array” (-a), I haven’t used the array yet.
Perl has a difficulty : you can implicit everything. Some guys abuse of it in scripting, like spirits, but it’s good for an onliner.

This line will print file1. Great (in fact implicit in “print $_” ; $_ is the variable where perl puts what you do not explicit). Printing is great but let do some awkish things :

perl -ane ‘/$m[aiy]/ && print $_’

That will print the lines that contain $ma, $mi or $my, (have a look at the article from karkoma about sed), patterns in perl are like sed’s ones but larger. Take a look at the tutorial of perl for pattern or type “perldoc perlreftut” if you have installed perldoc.

Well, just let do some sedish thinks :

perl -ane ‘s/

]*)>//; s/
/;print’ file1.html

replaces the paragraph in html( by newline () but keeps the options of the paragraph ($1, first match, here the parenthesis are not optional) in an html comment.

perl -F”:” -ane ‘/pascal/ && print $F[2]’ /etc/passwd

will print the UID of user pascal (third field), the field separator is “:” (-F$-1òý:òý)

perl -ane ‘/$m[aiy][^ s]*/ && print “line : $. variable : $&n”‘

will print the number of line ($.) where the variables that begin with “$ma”, “$mi” o “$my” and the variables that have matched the description ($&)

bad news, you received this bad MS file with carriage return (r) and newline and you want only the newline :

perl -pi.old -ane ‘s/rn$/n/;print;’ file1

and I obtain directly a file1 without carriage return and I have a backup of the original in file1.old (-pi.old)
you can have a look to a quick look at some useful perl onliners.