Saturday, January 24, 2009

Perl - simple log-filter script

Lets say we are having a log file in the following format (/var/log/messages format):
Jan 25 00:08:33 localhost kernel: imklog 3.21.9, log source = /proc/kmsg started.
Jan 25 00:08:33 localhost rsyslogd: [origin software="rsyslogd" swVersion="3.21.9" ] restart

Here how to write a simple perl script which will print the log file using a filter (in this sample I will filter the file by its modules : kernel, rsyslogd).

Script start:


# Log file name

sub read_from_file()
# The first (and only) parameter in the module filter string

# Open the file for reading, if cannot - exit
open (FHANDLE, "< ${FILE_NAME} ") || die "couldn't open the ${FILE_NAME} file!";

# Reading the file
while ()
# Parse the line into its parts using regular expressions
($date,$hostname,$module,$msg) = /^(.+?\s.+?\s.+?\s)(.+?\s)(.+?:\s)(.*)/;
# If ((the filter is not "ANY") and ( current line do not match the filter, in this sample - ignore case)) skip current line
unless (( ${MODULE_FILTER} eq "ANY" ) || ( ${module} =~ /${MODULE_FILTER}/i ))
# print current line
print $_;
# close file handle
close ${FHANDLE}

## Main
Script End;

If I'm calling the subroutine with the "ALL" filter, I will see all the file.
If I will call with the "KERNEL" filter, I will only see the first line.

Tuesday, January 20, 2009

Building Fedora 10 kernel

Preaparing the build environment:
In order to create the file system environment we need to run the following command where we want to build the kernel (If missing, install package rpmdevtools):

Now, We are having the rpmbuild directory which contain the following directories : BUILD, RPMS, SOURCES, SPECS and SRPMS.

Note: the rpmdevtools was changed between fedora 9 and 10, in 9 we had to call fedora-buildrpmtree.
Other note: Some of the operations required root permissions, you can run it
as root or use "su", just remember that the rpmbuild directory is expected in the current user home directory and pay attention to the directory permission.

To set the build in a specific path (e.g. ~/rpmbuild) add the following to the ~/.rpmmacros file:
%_topdir %(echo $HOME)/rpmbuild #path to your custom
build dir

Download and install the kernel source:
Now, we should downoad the kernel source from, since my kernel version is I will download the file kernel-

After the download completed, extract the rpm by typing (you can ignore the "warning: group mockbuild does not exist - using root" messages):
#rpm -ivh kernel-

Preparing the build (in my case, for i686):
#cd rpmbuild/SPECS
#rpmbuild -bp --target=i686 kernel.spec

Building the kernel rpm:
Note: For this sample, I will build the kernel without any configuration changes.

Go to the build directory and start the rpm build.
#cd rpmbuild/BUILD/kernel-2.6.27/linux-2.6.27.i686
#make rpm
This is going to take some time .....

Creating the ram disk:
initrd image creation:
Since the mkinitrd function searching the built modules under /lib/modules/, I created a soft link from there to the place we have built the modules
(there must be more elegant way ...)
#cd /lib/modules/
# ln -s <build path>/rpmbuild/BUILDROOT/kernel-
#cd <build path>/rpmbuild/BUILDROOT/kernel-.6.27.9-1.i386/boot
#mkinitrd /boot/initrd-

Installing the new kernel:
Now, We need to copy the generated files from the <build path>rpmbuild/BUILDROOT/kernel-
directory to the /boot directory in the target machine:

In the /etc/grub.conf file we need to add
an entry for the new kernel:
title myBuild (
root (hd0,0)
kernel /boot/ofer/vmlinuz- ro root=UUID=<your uuid> rhgb quiet
initrd /boot/ofer/initrd-

Reboot the machine, choose the new kernel in the grub screen, and that it :-)

Sunday, January 18, 2009

vmware tools for fedora 10

The vmware tools (VmwareTools-6.5.0-118166) installation went surprisingly fast (including the kernel modules compilation using script) on the fedora 10 kernel version except two issues:

During the X server configuration, I received an error which indicate that the vmware tools cannot locate the monitor, its seems like vmware looking for Xorg instead of Xfree86.
In order to bypass this issue we should create the following /etc/X11/xorg.conf (as root):
Section "Monitor"
Identifier "vmware"
And re-run the config tool.

The second problem was the “drug-and-drop”, IT DIDN'T WORK !!!, to fix it call /usr/bin/vmware-user as written in “
"You will need to either manually start /usr/bin/vmware-user or log out and log
back in to this desktop session to obtain the following features: guest
resolution fit, drag and drop, and file and text copy/paste. vmware-user is
configured to automatically start at a graphical login, but that won't take
effect until the next login."

If needed, Call the vmware-user every login using the application start-up list.

Activate conky upon startup

While using conky we can make it start with our system, The easiest way is to add it to the session.

Go to : System > Preferences > Personal -> Sessions -> “Startup Programs” , and add the conky to the additional startup progam list.

After the X server start, You will see something weird, the conky appear on the screen and then disappear under the background image, The problem is that the conky is starting to fast before the rest of the desktop component.

In order to fix it we will “tell” the conky to wait a while before starting ,create the following bash script conky_start:
sleep 10
conky &
exit 0

Change it permission to execute:
#chmod 755 /usr/bin/conky_start

Try to launch it manually to make sure you don't have any typo and change the session startup-programs to launch this script instead of conky.