Thursday, September 11, 2008

Parsing a text file line by line in ksh

This is how to parse a file line by line in ksh :


while read line
do
run you commands here
done < text_file.txt

Wednesday, September 3, 2008

Enabling xvid codec in Ubuntu 8.04

I usually convert video using a 2 pass process with ffmpeg. The command line is :
date;ffmpeg -i myinputfile.mpg -pass 1 -passlogfile vts.log -qscale 2 -vcodec xvid VTS_02_temp.avi;date;ffmpeg -i myinputfile.mpg -f avi -vcodec xvid -pass 2 -passlogfile vts.log -b 800 -g 300 -bf 2 -acodec mp3 -ab 128 myoutputfile.avi;date

When I tried to the first time on my new ubuntu 8.04, I got this error message :
Unknown codec 'xvid'

After googling on the web, I found the solution. The xvid codec along other non free codecs are not included in the Ubuntu repository. We need to use a separate repository call Medibuntu. This repository contains everything free and non-free for all the video processing needs. The web site is hosted on http://medibuntu.org.

A complete installation procedure is on the repository how-to section of the web site. In short, if you're using Ubuntu 8.04 on i386 architecture, these are the steps you need to enable the new repository :

sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list
sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update


Then you open up Synaptic package manager and do a search on ffmpeg and xvid. you should see quite a few files that need upgrade (a little yellow star on the package icon). Upgrade all packages and you should now be able to encode using xvid codec.

Thursday, August 28, 2008

Install various linux partition on USB drive

If you want to bring your favorite Linux distro with you, why don't you prepare a USB stick ? UNetBootin will do it for you. There are a windows version and a linux version. Check it out : http://unetbootin.sourceforge.net/

Friday, July 18, 2008

Taking control on a PC stuck at GDM

Have you ever been in the situation where you PC at work have rebooted and is now sitting at the GDM display waiting for you to enter a username and password ? Well this happened few times to me. The solution is rather simple. You only need to have an ssh access to your PC.

1 ) Logon to your PC using your ssh access.
2 ) install (if not already there) x11vnc : sudo apt-get install x11vnc
3 ) The tricky part is that gdm using a different xauth file than X11 server. So you need to find out which and where this file is. A simple ps -ef | grep gdm will give you the answer :

jboismar-desktop ~ # ps -ef | grep gdm
root 5683 1 0 11:12 ? 00:00:00 gdm
root 5684 5683 0 11:12 ? 00:00:00 gdm
root 6300 5684 0 11:31 tty7 00:00:00 /usr/bin/X :0 -br -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt7
gdm 6313 5684 0 11:31 ? 00:00:01 /usr/lib/gdm/gdmgreeter
root 6320 5726 0 11:33 pts/0 00:00:00 grep --colour=auto gdm

The part you need is : -auth /var/lib/gdm/:0.Xauth

4 ) then you launch x11vnc with this argument. I usually use root :
jboismar-desktop ~ # x11vnc -auth /var/lib/gdm/:0.Xauth

The last lines should look like this :
18/07/2008 11:35:18 WARNING: the warning message printed above for more info.
18/07/2008 11:35:18

The VNC desktop is: jboismar-desktop:0
PORT=5900

******************************************************************************
Have you tried the x11vnc '-ncache' VNC client-side pixel caching feature yet?

The scheme stores pixel data offscreen on the VNC viewer side for faster
retrieval. It should work with any VNC viewer. Try it by running:

x11vnc -ncache 10 ...

more info: http://www.karlrunge.com/x11vnc/#faq-client-caching


5 ) You can then run a vnc client to access your remote screen. Once you login, GDM will terminate to start the X server. Your x11vnc program will also terminate at this point.

Tuesday, July 15, 2008

Compiling Synergy on Ubuntu 8.04

I'm using a lot synergy at work to use one keyboard/mouse to control my laptop and my desktop. It's a wonderfull software. Unfortunately, it is buggy in Ubuntu 8.04. So I decided to re-compile and see if it is any better.

First, you need to get the latest cvs tree :
cvs -z3 -d:pserver:anonymous@synergy2.cvs.sourceforge.net:/cvsroot/synergy2 co -P synergy

now, go to synergy/src directory and try a ./configure. In my case it ended up like this :
checking for X... no
checking for XTestQueryExtension in -lXtst... no
configure: error: You must have the XTest library to build synergy

After googling everywhere, I finally found this page. So, to get the XTest library, we do :
sudo apt-get install libxtst-dev

Then we need to specify where synergy can get the X include and library files :
./configure -x-includes /usr/include -x-libraries /usr/lib --prefix=/usr

and voila ! The configure process should now be happy. You can then make and make install.

Tuesday, June 17, 2008

Determining version of Solaris

Ever wonder if you are running Solaris 32 or 64 bits ? You can find out with isainfo command.

[root@xxxxxx:/root]
#isainfo
sparcv9 sparc

sparcv9 means you are running 64bits version of the OS. To make sure, use :
#isainfo -b
64

This gives you the name of the instruction set(s) used by the operating system kernel components such as device drivers and STREAMS modules.

This command also gives you if your system runs 32 and 64 bits apps :
#isainfo -v
64-bit sparcv9 applications
32-bit sparc applications

Wednesday, May 21, 2008

Directory diff


When running fedora and KDE, I used kdiff3. Now I've moved to Ubuntu and gnome and was looking for a replacement. I found meld. It has all the features kdiff3 had. Here is a screenshot :


You can download it with the following command :
sudo apt-get meld

Bridged networking in Ubuntu with VirtualBox

I got so frustrated with the installation of vmware on linux ( having to apply the any any patch + editing files.... ) that I decided to try VirtualBox. What a surprise ! I found a very mature virtualization software. The installation went smoothly and the gui is very simple yet efficient.
The only drawback is the networking part. Basically VirtualBox is fine if one wants to run a VM with any OS to access internet. But if you want to create VMs and use them to host network services like Web servers, mysql servers and so forth, then the default network mode NAT will not let you do that.
You want to setup host networking ( or bridged networking ). Here is how I did it on Ubuntu 8.04 and VirtualBox 1.6.
Note : This is actually from the user documentation of VirtualBox page 75, chapter 6.7.1.1.

First you installed the bridge utilities :
sudo apt-get install bridge-utils

Then you define the bridge by adding the following section to /etc/network/interfaces :
auto br0
iface br0 inet dhcp
bridge_ports eth0

And restart the network :
sudo /etc/init.d/networking restart

You define a virtual interface using the VirtualBox tools :
sudo VBoxAddIF vbox0 br0
Here is the user running VirtualBox ( the one you logged in with in your ubuntu/gnome session ).

You're done with the command line configuration.
To tell VirtualBox to use the interface, select the virtual machine which is to use it in the main window of the VirtualBox application, configure one of its network adapters to use Host Interface Networking (using “Settings”, “Network”, “Attached to”) and enter vbox0 into the “Interface name” field. You can only use a given interface (vbox0, vbox1 and so on) with a single virtual network adapter.

Saturday, May 3, 2008

View directory tree and disk usage in Windows


I know this isn't a unix software but it is similar to Kdiskview ! I missed so much this kind of tools when trying to find where windows disk space has gone. And I must say, this freeware is very well made. Congrats to the developers !!! here is their website.

Thursday, April 24, 2008

One mouse and keyboard to rule them all

If you have several boxes sitting at your desk and do not want to use one keyboard and mouse for each of them, you could install and setup Synergy software. It's a freeware and works great ! it's a client server architecture that communicates through IP. A daemon (synergys note the s for server) runs on the machine that has the keyboard and mouse and listen for clients. The client (synergyc note the c for client) connects to it.

The configuration is VERY easy. Take a look at my config file :




















Section:screens

Laptop:

Desktop:
End

Section:links

Laptop:


right = Desktop

Desktop:


left = Laptop
End

Section:aliases

Laptop:


laptoprealname

Desktop:


desktoprealname
End

Section:options

switchDelay=1
End




Now, few explanations about that config file. In the screen section, you list all your systems and call them by a convenient name. I used laptop and desktop but you can use whatever suits your environment.
The links section describes how your screen are physically setup.
The aliases section is here to translate the convenient machine names you choose to real name or ip. In my case the file /etc/hosts contains entries for laptoprealname and desktoprealhostname.
The switchDelay in the last section set the number of ms to wait when the mouse reaches a screen edge before it crosses over next screen. I put 1 there meaning there will be almost no wait.

Now, how do you start all these.... For the server, you run synergys -f. It should read the config file in $HOME/.synergy.conf.
Then, on the client, you run synergyc -f -1 .

You should now be able to use only one mouse and keyboard to control your machines.

Thursday, April 10, 2008

Dual head with xrandr

This was posted by

I've got Ubuntu 7.10(gutsy) running pretty well on my DELL Latitude D505 laptop. I'll try to explain how I configured extended desktop with a NEC 19'' LCD monitor.
We will use xrandr utility to configure multiple screens. Before using xrandr you must check xorg.conf file ( /etc/X11/xorg.conf )


Section "Screen"
Identifier "Default Screen"
Device "Intel Corporation 82852/855GM Integrated Graphics Device"
Monitor "Generic Monitor"
Defaultdepth 24
SubSection "Display"
Depth 24
Virtual 2304 1792
Modes "1280x1024@75" "1024x768@60"
EndSubSection
EndSection

The Virtual keyword is important. Sum of resolution widths and sum of resolution heights of two monitors are written in Virtual.
For example : 1280 + 1024 = 2304 and 1024 + 768 = 1792


You must restart X server after updating xorg.conf file. ctrl-alt-backspace is the shortcut to restart X. After successfully restarting X server, run the following commands:

xrandr --output VGA --mode 1280x1024
xrandr --output LVDS --mode 1024x768
xrandr --output VGA --right-of LVDS
First command sets VGA (19'' LCD monitor) resolution to 1280x1024. Second command sets laptop monitor resolution to 1024x768. The last command places the extended monitor (VGA) right of laptop monitor. That's it. At least it works for me.

Friday, April 4, 2008

Enabling compiz for X3100 graphic card

If you install Ubuntu on a PC with a X3100 (aka 965), the right driver will be in place. So don't do as I did ;-) trying to upgrade the driver or editing the xorg.conf to see what it going on...
The reason why it is not working out of the box is because it is meant that way. Developers have black listed the x3100 due to some limitation to the with the current intel driver. So if you want compiz, you have to take the X3100 out of the black list. To do so, edit the file /usr/bin/compiz and comment out (add a # sign at the beginning) the following line :

T=”$T 8086:2982 8086:2992 8086:29a2 8086:2a02 8086:2a12″ # intel 965

So, in the end it should look like this:

#T=”$T 8086:2982 8086:2992 8086:29a2 8086:2a02 8086:2a12″ # intel 965

Then you can go to system->preferences->appearance and click on the "Visual Effect" tab to enable compiz. It worked like a charm for me (Toshiba A200 FT-1).

Thanks to this post : http://temporaryland.wordpress.com/2007/12/06/finding-the-right-distro-for-my-thinkpad-followup/



Thursday, March 27, 2008

unix2dos shell script

To convert a file from unix format to DOS, you can use the following script. Note that on recent unix systems this script comes built-in....

#! /bin/sh
if [ ! "$1" ] ; then
echo `basename $0` file ...
echo ' convert' filenames from unix to dos file format
exit 1
fi

while [ "$1" ] ; do
TMP=$1.$$
awk 'sub("$", "\r")' $1 > $TMP
cp -f "$TMP" "$1"
rm -f "$TMP"
shift
done

Thursday, March 6, 2008

dos2unix shell script

To convert a file from DOS format to unix format, you can use the following script. Note that on recent unix systems this script comes built-in....

#! /bin/sh
if [ ! "$1" ] ; then
echo `basename $0` file ...
echo ' convert' filenames from dos to unix
exit 1
fi

while [ "$1" ] ; do
TMP=$1.$$
if tr -d '\r' <"$1" >"$TMP" ; then
cp -f "$TMP" "$1"
fi
rm -f "$TMP"
shift
done