Archive for December, 2006

Bash – strings with multiple words inside them

Thursday, December 21st, 2006

Let’s assume we have a file containing lines such as this:

first last

one two

three four five

If we write a simple script to deal with each line in a turn, we would write something like this:

for i in `cat file`; do echo $i; done

This would echo, however, each word at its turn. If we want the whole line in this echo, we need to set BASH special variable: IFS.

Example:

export IFS=$’n’ ; for i in `cat file`; do echo $i; done

This would do the trick. We define the Internal Field Separator to be newline only, and not newline, spaces and tabs, as the default goes.

The credit for this piece of information I can easily give to this site. Thanks, guys.

Xgl, ATI fglrx and Dual-Head setup

Monday, December 11th, 2006

I’ve had a problem for a long while now configuring Xgl on my Dual-Head setup, using GLX and fglrx driver. I have been using 1280×1024 on both of my screen, so my total resolution was 2560×1024. When using Dual-Head setup in “Wide Desktop” mode (via the option Option “DesktopSetup” “horizontal” in the Device section in /etc/X11/xorg.conf), I was unable to load Xgl. When hashing this specific option, I reverted to mirror-mode (two screens show the same content), and Xgl worked fine.

Since I’ve seen dual-head setups (screenshots on the net), I assumed that the problem was due to ATI drivers. I didn’t know how accurate I was.

It appears, based on post in this forum, that fglrx (ATI Drivers) do not function in a resolution beyond 2048. I have tried alterning the max resolution per-screen to 1024×768, and although I get huge icons now, Xgl works correctly with Beryl (version 0.1.3). I have used a combination of this excellent guide, and of a link to the new SVN Beryl binaries, available for Ubuntu here. So far, it seems to work nice, although it forces me to use low resolution at the moment. I think I will just go and buy myself a nice Dual-head capable AGP NVidia card.

LVM Snapshots with MySQL

Saturday, December 2nd, 2006

Nowadays, when LVM2 is common and is actually the default in installation of RedHat based distributions, using its snapshot capabilities can save lots of grief when files are deleted or when you need to revert to a day in the past – both for your files and for your MySQL DB.

I have created a script which is based on the following assumptions:

1. Inside /etc/samba/smb.conf there is a directive such as: include /etc/samba/smb.conf

2. There is a single LV containing all the system’s data. It doesn’t occupy all the physical disk (or, for the matter, the entire VG space). Free space is 10-20% of disk size

3. Specific share directives are located inside /etc/samba/smb.conf.snapshot.full. An empty file /etc/samba/smb.conf.snapshot.empty exists.

4. I do not trust all places to hold a password for their MySQL (although it is advised!). This script assumes such password doesn’t always exist

5. The script mounts the snapshot read-only just after creating an empty file with the date of the snapshot inside its root.

The script is attached here. take-snapshot.txt