Archive for the 'Linux' Category

Bash script woes

Monday, 28th May, 2007

I had an opportunity to play with Bash script on Friday. My task was to write a small deployment script to grab our server class configuration settings from subversion and rsync them to the appropriate machines.

This was easy enough, a couple of commands to subversion, rsync and some glue and I’d be done. However, an hour into writing it I wish I’d used PHP or used my time to learn how to do it in Perl.

For one, a hash of arrays doesn’t sit well in Bash script. I wanted to define a list of servers for each class. In PHP the code would have been as simple as:

<?php

$servers = array(
  'web' => array('server1', 'server2', 'server3'),
  'db'  => array('server4', 'server5', 'server6')
);

?>

Fortunately I was able to work around this with separate arrays for each class. What I couldn’t get around was the pain I had to endure to pass an array as an argument to a function.

Passing an array involves loading the space-separated elements of the array into a variable with command substitution.

Taken from Chapter 33 of the Advanced Bash-Scripting Guide.

printarray () {
  local passed_array
  passed_array=( `echo "$1"` )
  echo "${passed_array[@]}"
}

original_array=( element1 element2 element3 element4 element5 )
argument=`echo ${original_array[@]}` # command substitution
printarray "$argument"

This is just clunky and showed me that for anything more than basic conditional logic I’m better off investing some time in learning Perl.

Debian Quirks

Saturday, 11th November, 2006

Just a tip for anyone else Googling this, if you’re trying to install the DNS utility dig on Debian the obvious doesn’t work:

# dig
bash: dig: command not found
# apt-get install dig
Reading Package Lists... Done
Building Dependency Tree... Done
E: Couldn't find package dig

This is what you need:

# apt-get install dnsutils

Linux answer to Aero: Xgl

Thursday, 15th June, 2006

Well it seems I was a little slow off the mark with spotting this but I stumbled across Xgl today. What is Xgl? (quote lifted from Wikipedia)

Xgl is an X server architecture, started by David Reveman, layered on top of OpenGL via glitz. It takes advantage of modern graphics cards via their OpenGL drivers, supporting hardware acceleration of all X, OpenGL and XVideo applications and graphical effects by a compositing window manager such as Compiz.

It certainly looks impressive, especially the rotating 3D desktop demo that Novell have showcased. Shame it doesn’t support multiple monitors though.

If I’m honest I did think to myself, after the novelty factor has worn off, how much will this improve productivity? Sure spinning the desktop on a 3D cube looks cool but I never used the multiple desktops that were available in Linux anyway, it was usually a case of “out of sight, out of mind”.

After a few days of using Windows XP’s Luna theme I found it bulky (and always reminds me of fisherprice) and switched back to Windows Classic, I’ve found most of people at work have too.

Check out Novell’s Xgl showcases.

MySQL 5.0 not so production ready?

Monday, 29th May, 2006

For several months now I’ve thought MySQL 5’s push to a production ready status was more of a political move than technically justified. First I read this and again today when it came time to compile any MySQL support into PHP 5.1.4 on my newly installed Linux box I ran into problems.

We’re in the process of making the move to MySQL 5.0 at work too; however since we’re moving from 3.23.x there’s nothing too clever going on with the SQL. I always check up on the changes made in recent point releases. MySQL 5 scares me because of some the bugs still unpatched (SELECT DISTINCT queries sometimes returned only the last row), we’re now on more point releases for 5.0 than 4.1 (21 vs 19).

Goodbye Fedora, Hello Slackware

Sunday, 28th May, 2006

So I got XDebug working a couple of weekends ago. After much fun trying to install KCacheGrind on Fedora and setting up X forwarding to my Windows box I finally saw the fruits of my labour.

KCacheGrind on Windows via XMing

I was impressed with the Call Graph which shows the flow of execution. This is a framework I spent some time developing in April for a music store. I hope to make more use of this profiling at work some time.

Ironically just as I had got this working my Fedora install starts to play up (after running fine with no X for 18 months beforehand). The filesystem would become read-only after several hours idling. Turns out a part of the filesystem was corrupt; I was constantly having to reboot and run fsck to correct these errors. However yesterday fsck took ages to sort things out and more and more files were being lost so I figured it was time to re-install.

Fedora has been my distribution of choice for a couple of years but this is the second time I’ve had to wipe the drive due to disk errors. I think this is largely due to heat issues, my linux box is a shuttle PC and it gets pretty hot compressing off-site backups from this co-located server come 5am! After re-partitioning, formatting and running check disk in Windows, the drive seemed completely healthy (most odd considering on boot it was reporting “S.M.A.R.T bad” errors). When re-formatting in Slackware and checking for bad sectors - none found! Strange albeit good news I guess.

So why Slackware? Well after the messing around required to get KDE up and running on Fedora I wanted to move to a pro-KDE distribution. I’m not a fan of managed distro’s like Gentoo (emerge yuk!). Call me a control freak but too much happens behind the scenes, I like to install the major applications from source so unexpected changes don’t occur when you update system packages. I also prefer the default layout of Apache/PHP/MySQL, upgrades are easier, no waiting on your fav distro to prepare customised packages.

Slackware has thrown me a few curve balls early on though (just getting vim working correctly!). I forgot to install atk, which appears to be a GNOME library (so much for a GNOME free system), and ‘vi’ was symlinked to elvis (which from my brief experience seems horrible). Turns out Slackware is BSD init based not System V, meaning it doesn’t use the rc.1, rc.2 directories like Redhat etc. This was enough to trip me up when trying to install the mysql.server init.d script, easily solved though:

cp support-files/mysql.server /etc/rc.d/rc.mysqld

You are currently browsing Mostly PHP MySQL Javascript Linux, some Ruby Java frameworks agile methods but overall web programming and software development in general archives in the Linux category.

Categories

My Bookshelf

PHP in Action: Modern software practices for PHP Agile Web Development with Rails
xhtml 1.1 compliant   xhtml 1.1 compliant