Google Buzz

I heard about Google Buzz on CBC Radio yesterday… came home and tried to connect but it wasn’t activated. What’s all this Buzz about? Today, while using Gmail, I noticed the icon for it, opened it up, and added some “connected sites”. I’ve already had two conversations about a picture of a turtle I took a few years back. Awesome.

Seems easier to use than Facebook too.

Recursive find and replace

From time to time I find myself wanting to replace a bit of text, in multiple files, throughout a huge directory tree (particularly in the case of a WordPress migration).

Here’s a method I frequently use (other examples I’ve seen out there make use of perl, xargs, grep, etc.):

user@host:~$ cd Directory_To_Start_From
user@host:~$ find . -type f -exec sed -i 's/Text_To_Find/Replacement_Text/g' {} ;

The find command will return a list of all the files in the directory tree and execute the sed command on each one it locates. In the example below, I added the “-name” option to the find command to allow for working only on files with the .js extension:

user@host:~$ cd website
user@host:~$ find . -type f -name "*.js" -exec sed -i 's/var pageName="example page";/var pageName="Final Page";/g' {} ;

In the next one, the text to find and replace has special characters (in this case the ‘/’ in the URL).

user@host:~$ cd website
user@host:~$ find . -type f -exec sed -i 's/http://www.example.com/old_directory//http://newsubdomain.example.com/new_directory//g' {} ;

See the following links to read more about escaping special characters:

Sloppiness at 1and1

So I have been noticing issues with 1and1 again. Yesterday when trying to get into my hosting control panel at admin.1and1.com, I received a “HTTP Error 503 Service unavailable” error, and thought to myself… really, on the admin panel… really?

Today while checking out my own site, I noticed that all of the PHP files I tried browsing to returned “500 Internal Server Error” errors.

Now this has gone too far… so I called them up. At first the person I talked to explained that I needed to force PHP5 using a .htaccess file, and proceeded to tell me that they could make the change for me. Calmly, I responded by saying that I did not want a change, and that it had been working fine the way it was for months.

She put me on hold, and while I waited… it started working. She told me that the shared hosting server “had a glitch”.

Afterwards, I ssh’ed into my server. Look what I found:

(uiserver):uXXXXXXXX:~ > ls -al
total XX
-rw-r--r--  1 uXXXXXXXX XXXXXXXX   16 Feb  3 14:06 info.php

I thought, “weird, I didn’t put that there”.

(uiserver):uXXXXXXXX:~ > cat info.php 
<? phpinfo(); ?>

Shame on you 1and1, for not cleaning up after yourself. Well, I guess you get what you pay for.

Databases on 1and1

After wanting to test WordPress 3.0 on a 1and1 hosting account, I ran into the following issue… the particular setup I was dealing with had only one database available, and it wasn’t MySQL 5, but instead MySQL 4… furthermore, it was a version lower than 4.1.2, which more recent versions of WordPress require as a minimum.

So after doing a bit of research on what others had done, I went about fixing the problem. Interestingly enough, 1and1 could have made some money in this situation if they would allow customers to simply purchase another database to add to their packages, but no, they want an entire upgrade to be purchased.

The first step was to backup the website and database. I ssh’ed into the web host:

username@localhostname:~$ ssh $username@example.com

Then I backed up the database. The command below will dump all of the databases on the host (in this case, only one MySQL 4.x database) into a dated bzip file, in the home directory.

username@remotehostname:~$ mysqldump -C -A -u $databaseUsername -h $databaseHostName -p$databasePassword | bzip2 -cq9 &gt; ~/`date +%F-%I-%M-%p`-db-backup.sql.bz2

Now to backup the site itself (not only in case disaster struck, but this would get a local copy of the sql dump I just made as well). On a local OS X workstation (or Ubuntu, if that suits your tastes) I ran something similar to the following:

username@localhostname:~$ mkdir ~/website_backups
username@localhostname:~$ rsync -avz --exclude="logs" $username@example.com: ~/website_backups/

From there, I was able to log into the 1and1 control panel and delete the existing database. This allowed me to setup a new one, and in particular, choose MySQL 4 or 5 as the type.

Back to the 1and1 hosting account:

username@localhostname:~$ ssh $username@example.com

I uncompressed the sql dump:

username@remotehostname:~$ bunzip2 2010-01-14-01-59-PM-db-backup.sql.bz2

and was greeted with the raw sql in the file, “2010-01-14-01-59-PM-db-backup.sql”. From here it was only a hop skip and a jump away to restoration. It was necessary to edit the sql file in order to have it restore properly to the newly created database that was just created:

username@remotehostname:~$ nano -w 2010-01-14-01-59-PM-db-backup.sql

And I changed the $oldDatabaseName to $newDatabaseName.

--
-- Current Database: `$oldDatabaseName`
--
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `$oldDatabaseName`;
USE `$oldDatabaseName`;

ctrl+o, enter, and ctrl+x, to save the file and exit nano. The sql dump was now ready to restore to the new database.

username@remotehostname:~$ mysql -u $databaseUsername -h $databaseHostName -p$databasePassword $databaseName &lt; 2010-01-14-01-59-PM-db-backup.sql

The only other things to do were to update any existing applications that needed the new database name, username, hostname, and password.

As a note, if you are updating a WordPress install to point to a new database, this info can be changed in the file, wp-config.php.

WDS Bridging Experiences

At the moment, our best solution for network coverage to multiple buildings is wireless. I have been planning out various solutions to improve our system (fiber optics, dslam, or a better wireless setup) but wanted to share what we have now and how well it has worked in this particular area of our property.

WDS Repeating Map

The image above shows the main buildings that are being linked. The main router sits in an upstairs window and is a:

Linksys WRT300N

  • Runs DD-WRT V24 – SP2 (Beta)
  • Has original antennas
  • Has the following properties set (among others, these are the interesting ones)
    • Wireless – Basic Settings
      • Mode: AP
      • Network Mode: BG-Mixed
      • Channel: 11 – 2.462 GHz
      • SSID Brodcast: Enable
    • Wireless – Advanced Settings
      • TX Power: 71
    • Wireless – Security
      • Security Mode: WEP (I haven’t tested WPA2 with WDS yet, and I understand that WEP can be cracked easily)
    • Wireless – WDS
      • The three router’s MAC addresses are filled in, and are set to “LAN”

The three client WDS routers are also sitting in windows, and are on the first level of the buildings that they are in. They repeat the same SSID, and run on channel 11.

Buffalo WLI-TX4-G54HP

  • Originally purchased as an ethernet bridge, it is now running DD-WRT V24 – SP2 (Beta)
  • Replaced the stock antenna with a 9 dBi omni-directional
  • Is on the 72.6m link

(2) Belkin F5D7230-4 routers

  • WDS on the stock firmware works with DD-WRT, sweet!
  • These are unmodified, running with their tiny fixed (two) omni-directional antennas
  • One is on the 35.4m link, and the other on the 88.5m link

This setup has been going for weeks without an issue, and has served upwards of six families, a two person office, a fifteen to twenty person office, and a classroom with sixteen students.

We have other areas on the same property that have wireless access between buildings, but are nowhere near as complete as this arrangement. If we do end up using wireless to unify the property’s networks, then I will start looking into site to site links, multiple gateways, OLSR, and other mesh technologies. I have my doubts as to how well WDS scales. Has anyone had positive results with professional mesh solutions built on DD-WRT and Linksys hardware?

Time Machine Size Limits

So I have this new My Book World Edition, and I set it up to allow for Time Machine backups. The problem? On OS X, Time Machine wants to eat up almost the entire amount of free space before it goes about deleting old files… (un)conveniently there is no option to restrict the size of the backups.

Never fear… I google’d a bunch and found that if you run the following command on the Mac doing the backups:

defaults write /Library/Preferences/com.apple.TimeMachine MaxSize 209715200

It doesn’t appear to do anything (or may possibly do something else that isn’t related to what I was after). :-)

So, I went about it in a different manner. If I clicked on the Time Machine icon (rotating clock) in the menu bar, and clicked “Enter Time Machine”… exited the GUI of Time Machine, and then opened terminal, I could do the following:

  1. Become root:
    sudo -s
  2. Goto the /Volumes directory, and look for which folder is mounted for Time Machine backups:
    cd /Volumes &amp;&amp; ls -l
  3. Enter the folder that is mounted for Time Machine backups:
    cd $Mount_Point_For_Backups
  4. Look for the .sparsebundle file that is being used for backing up the workstation:
    ls -l
  5. Resize the sparsebundle file:
    hdiutil resize -size 200g $hostname.sparsebundle

The sparse image is then resized, and Time Machine will report that there is only around 200 gigabytes total available space rather than around a terabyte (which is the original size of the drive). :-)

MBWE SSH access

Just setting up a My Book World Edition (1TB, WDH1NC10000) and would recommend the following steps after purchase for SSH access:

  • Login to the MBWE’s “Network Storage Manager” by typing the unit’s IP address into a web browser and then authenticating with a valid username and password
  • Click the “Advanced Mode” link
  • Click the “Advanced” icon
  • Check the “Enable” checkbox under the “SSH Access” area
  • Click the “Submit” button

Now SSH into the MBWE using the username, “root”, with the default password, “welc0me”. After logging in, be sure to change passwords for the root user by issuing the command, “passwd”.

A few other things I noticed were necessary, if you want ssh access via public key authentication:

  • Copy the contents of the public key file from the client (usually ~/.ssh/id_dsa.pub) to the MBWE on a new line under /root/.ssh/authorized_keys
  • Login as root to the MBWE and issue the following command in the terminal:
    chmod go-w ~/

    This was neccessary as when I tried to authenticate via public key, I was getting the following in /var/log/messages if I didn’t, “Authentication refused: bad ownership or modes for directory /root

Office Compatibility

OpenOffice or Microsoft Office. Use either. It’s like OS X vs. Linux… whatever tool that is best for the job right?

Here’s how you can make the two play a little nicer…

OpenOffice

Users with older versions of Microsoft Office Products, including Word 2000/2002/2003, Excel 2000/2002/2003, PowerPoint 2000/2002/2003)

Users of Microsoft Office 2007

Renaming MP3s in Bash

It seems like this comes up every now and again, but I end up forgetting how to do it. So, I will post the example here, where it will live forever on the intarwebs.

While there are a ton of ways to script this, using Bash, cut, ls, find, grep, sed, awk, perl, etc… In this particular instance, I find myself with a directory of about fifty files, each named in the following manner…

  1. 01 Song Title.mp3
  2. 02 Another Song Title.mp3
  3. 02 Same Number Song Title.mp3
  4. 03 Author – Title.mp3

Bash and cut to the rescue. The following code provides for each file in the current directory to have the number stripped off of the front, even it has spaces in the filename.

#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "nb")
for f in *; do
    mv "$f" "$(echo $f | cut -c 4-)"
done
IFS=$SAVEIFS