Access Dropbox From Linux Server Command Line

DropboxSharing files between VM’s can be a pain, especially if your VM is running on a text based server without UI. For example, I start up a new VM for almost anything and I deal with up to 20 different sites and application and every one has it’s own VM.

VMWare provides it’s “Guest Additions” and that includes folder sharing. It works fine on desktop os’s, but on the command line we have to mount it using VMWare’s file system, which can be a bit cumbersome. A much simpler and easier way to share files is via USB or DropBox. Getting the DropBox sync daemon to run is really easy and once running, anything you add to DropBox will be synced to your VM transparently and at network speed.

If you don’t already have a DropBox account setup, get a free one here. Now on to the steps to get the sync daemon up and running.

Steps:

SSH to your Linux server and change to your home directory.
cd ~
for 32-bit os:
wget -O dropbox.tar.gz “http://www.dropbox.com/download/?plat=lnx.x86″
for 64-bit os:
wget -O dropbox.tar.gz “http://www.dropbox.com/download/?plat=lnx.x86_64″
After the file “dropbox.tar.gz” downloaded properly, then extract it
tar -xvzf dropbox.tar.gz Read more »

Cross deleting records from multiple tables in mysql

I’ve been asked many times how to delete records in multiple tables in MySQL. Here are couple of methods that should get anyone started.

Simple Inner Join Method

The simple inner join method uses commas with an implicit inner join like in the example below. Here we’re using an items and price table, where each table has an itemId field which is what we join them on.

DELETE i.*, p.*
FROM items i, price p
WHERE i.itemId = p.itemId
AND i.itemId = 101

Traditional Inner Join Method

In the traditional inner join we’re keeping the join statement clear of the where clause, but it works as well. Whatever personal preference you may have. Note that you can delete individual table records from one table only, if you require to do so.

DELETE i.*, p.*
FROM items i
INNER JOIN price p
ON i.itemId = p.itemId
WHERE i.itemId = 101

Read more »

How To Clone A Virtual Machine In VirtualBox

Moving, cloning and modifying Virtual Machines and their associated Virtual Hard Disks in VirtualBox has been no easy task and to make matters worse, are poorly documented at best. In this guide, we’re using VirtualBox 3.2.10 r66523 running on Ubuntu 10.10 64bit host operation system.

Merge Snapshots

Merge all snapshots that we want to be included, delete the ones we don’t want. Unless we do this, we only get the base version and loose all changes contained in those snapshots.

Run VBoxManage

Using VBoxManage clonevdi to copy the virtual hard disk to a new VDI file. The basic syntax is: VBoxManage fullPathTooldVdiFile fullPathTonewVdiFile. We need to ensure that a hard disk with that name does not already exist, otherwise we’ll get errors.
VBoxManage clonevdi /data/VirtualMachines/Windows7.vdi /data/VirtualMachines/Windows7_clone.vdi

Add Disk To Virtual Media Manager

We’ll add the new created hard disk to the Virtual Media Manager. This step ensures that the hard disk has been properly cloned, has the proper permissions and that there are no conflicts with other disks and virtual machines. In VirtualBox, select File -> Virtual Media Manager -> Add and select the cloned file, in our case Windows7_clone.vdi. If there are no errors, we should now see the hard disk listed among the others and are ready to proceed with the new Virtual Machine.

Create new Virtual Machine

In VirtualBox, select Machine -> New  and proceed with the steps to create a new Virtual Machine. At the point we we select a hard disk, click existing and select our new disk.
Start up the new Virtual Machine and change hostname in /etc/hostname and eventually the network configuration in /etc/network/interfaces.

Fix for Mac OS 10.6.5 apachectl: line 82: ulimit

Mac OS 10.6.5 + apachectl: /usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

After the upgrade to Mac OS 10.6.5 a bug seem to have snuck in where apachectl tries to re-set ulimit to unlimited. The error appears as such:

/usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argument

While apachectl was working flawless before the upgrade to Mac OS 10.6.5, I suspected the two were related. After a quick search into what the update entailed, I found that Apple upgraded to Apache 2.2.15, which in turn patched a number of vulnerabilities. As it turned out, one of those changes broke the apachectl script.

Referring to line 82 of apachectl, the shell script was referring to the ULIMIT_MAX_FILES variable that was trying to set to unlimited, which read:

ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"

Changing the line as follows fixed the problem:

ULIMIT_MAX_FILES="ulimit -S -n 1024"

Should you be running a high amount of vhosts or do some testing that requires a significant amount of file descriptors, set this number higher accordingly.

Setup Puppet to configure your network servers

Growing companies at some point are faced with the increased workload to setup, configure and maintain their servers and applications. Administrators try to script repetitive tasks and ultimately look for solutions that are scalable and provide a central management tool base. There are several software packages available, commercial and open source ones.

Puppet is probably the most used open source configuration management package available today and more system administrators and software developers are interested in setting it up within their environment. An excellent book about Puppet (Pulling Strings with Puppet) is available and so are numerous online articles and tutorials. However, lots of online resources are just not quite complete and can lead to lots of frustration, especially in the setup and configuration of Puppet.

So here is another step by step tutorial about how to install and setup Puppet to the point where we can run a simple recipe residing on the server (puppetmaster) and execute on the client. For this illustration we’ll install Puppet on Ubuntu 10.10 using a deb package.

Configure Network and DNS

Setting up configure hostnames on server and client is crucial. Since Puppet uses self signed certificates to secure communication, it’s essential that network is setup properly and hostnames are configured with fully qualified domain names.

Let’s open /etc/hosts and add the necessary entries. (note: If you use a DNS server in your network, those setting changes should be made on your DNS server and not the hosts file)

 Read more »

HTML5 Open Source Framework for iPad E-books

Baker FrameworkThe Baker E-book Framework is a free, open-source platform to create e-books for the iPad. The framework was developed by a team of Italian software geeks, allowing designers and web developers to transform fixed-width HTML5 pages into an e-book format and subsequently publish the finished product. All publishers have to do is follow the Apple App Store submission guidelines.

The first step involves creating a HTML5 version of your book with fixed width of 768 pixels that works and looks fine using Safari in iPad or via downloadable support CSS at Baker’s site. Keep all files in a flat directory called book and name the html files according to their page number (eg. 1.html, 2.html ….) which is the HPub format. The naming convention is still somewhat strict, but that will change over the next few releases.

Finally download the Baker Framework and follow the simple instructions contained in the readme.txt file:

  • Rename the Xcode project
  • Include your book
  • Include your icon
  • Follow the App Store submission instructions

You can check out a sample book created by the Baker folks, 5×15 Tokyo.

Casali and his team hope their creation will lead to more beautiful e-books and digital magazines on the iPad, and for other WebKit-enabled devices later.

You can download the Baker Framework files at the official site, and you can also join the project itself on GitHub.

Install and configure puppet server (puppetmaster) on Ubuntu 10.10

Before installing and configuring puppet server (puppetmaster), ensure that your network is properly setup. Configure Puppet Server on Ubuntu 10.10 is easy and straight forward. It’s those subleties about the network configuration and necessary puppet recipes and files that can make our lives miserable.

To install Puppet, choose one of the following methods (we will use the Ubuntu Package)

Using package manager of your distro

  • RPM (Fedora) for Red Hat, Fedora (puppet-server for server, puppet for client)
  • DEB (Debian) for Ubuntu, Debian (puppetmaster for server, puppet for client)

Installing from source: (note: you will need to have Ruby installed on your system prior to installing Puppet)

  • download the latest version from puppetlabs
  • # tar -zxf puppet-0.xx.x.tgz
  • # cd puppet-0.xx.x
  • # ruby install.rb
  • # puppet –version (to verify installation)

Using Ruby Gem: (note: you will need to have Ruby and Ruby Gem installed on your system prior to installing Puppet)

# gem install –remote –source http://reductivelabs.com/downloads puppet

Read more »

Mac OS X 10.7 Lion – The Latest And Greatest?

Mac OS X LionInvites went out this week for “Back to the Mac”, an event happening on October 20, which includes a sneak peek of the future version of Mac OS X.

Whether 10.7 is a completely revamped OS or just an extension to 10.6 remains to be seen, however if one considers the minor progression of Leopard (10.5) to Snow Leopard (10.6), which was more like a revision than a version, then the designation of “Lion” (10.7) should bring a lot of powerful changes. We’re excited!

Apple started using wild cats as nicknames for the release of OS X. 10.0 was named “Cheetah”, 10.1 became “Puma”, 10.2 was “Jaguar”, 10.3 was “Panther”, 10.4 was “Tiger”, 10.5 was “Leopard” and the latest version, 10.6 is named “Snow Leopard”. These were internal code names at Apple, which as we all know became a successful marketing strategy for the OS X. And at this point it looks like OS X 10.7 will be named “Lion”.

Install and configure Puppet Client on Ubuntu 10.10

After we have configured our network and installed, configured and verified our Puppet Server (puppetmaster), it’s now time to install our first puppet client and configure it to receive a signed certificate and puppet recipes. If you haven’t performed those pre-requisite setups, please start with Setup Puppet to configure your servers.

Let’s first install puppet from the ubuntu package:

# apt-get install puppet

Then we start our client

# puppetd –server puppet-server01.example.com –verbose  –waitforcert 60

A peak at /var/log/syslog confirms our request for a certificate: Creating a new SSL certificate request for puppet-client01.example.com
And the same log on the server should contain: puppet-master[617]: puppet-client01.example.com has a waiting certificate request

If this state on the server is confirmed, it’s time to sign the certificate on the server:

# puppetca –list (and again we should see the hostname of our client that has requested the cert)

# puppetca –sign puppet-client01.example.com

We should get confirmation as such: notice: Signed certificate request for puppet-client01.nextpt.com. Anything else or errors will likely point towards network and/or dns configuration issues.

If you have followed our tutorial on how to setup puppetmaster, you should now have htop installed on your client. Also check /var/log/syslog for additional info.

Finally we should enable puppet to start on reboot. We do this by editing /etc/default/puppet and set START=yes.

Install Redmine using Passenger via Apache on Ubuntu 10.04

Installing Redmine on any system has been a daunting task for many, especially work thru countless dependencies and linking apps to make the application available via Apache. Since Ubuntu 10.04, Redmine can now be installed via apt or aptitude, and no doubt the process is much easier, but by no means just as straight forward as we’re used to.

To get Redmine up and running over Apache on Ubuntu 10.04, these basic steps are required:

  1. Install Apache2, Mysql Server, Subversion, extensions and utilities
  2. Install Redmine via apt
  3. Test Redmine using Webrick
  4. Install Passenger

1. Install Apache, Mysql Server and necessary extensions and utilities

$ sudo apt-get install build-essential apache2 apache2-threaded-dev apache2-suexec-common libapache2-svn libmysqlclient15-dev

2. Install and configure Redmine

$ sudo apt-get install redmine redmine-mysql subversion

Read more »

WITH (NOLOCK) table hint equivalent for MySQL

I don’t remember how many times I was asked about an equivalent term of the infamous “NOLOCK” hint for mysql database server, hence I thought it was worth to write about it here. “WITH (NOLOCK)” is a transaction isolation levels that defines how data is available during an update, or with other words it is a property that defines at what point changes made by an update operation will become available in a row, table or database to other processes.

The official SQL standard defines four isolation levels:

READ COMMITTED
READ UNCOMMITTED
REPEATABLE READ
SERIALIZABLE

Oracle, SQL Server and MySQL support isolation levels. During an operation, the database engine places certain locks to maintain data integrity. Different types of locking apply to different databases (Oracle vs. MySQL), or table types (eg. MyISAM vs. InnoDB).

When WITH (NOLOCK) is used with SQL Server, the statement does not place a lock nor honor exclusive locks on table. The MySQL equivalent is READ UNCOMMITTED, also known as “dirty read” because it is the lowest level of isolation. If we specify a table hint then it will override the current default isolation level. MySQL default isolation level is REPEATABLE READ which means locks will be placed for each operation, but multiple connections can read data concurrently. Read more »

Using Regular Expression In PHP – The Basics

regular expressions cookbookRegular expressions are a powerful tool for finding, examining and/or modifying text. Regular expressions themselves are, with a general pattern notation almost like a mini programming language, allowing you to define and parse text. They enable you to search for patterns within a string, extracting matches flexible and precise. However, you should note that because regular expressions are more powerful, they also suffer from added overhead and are slower than the more basic string functions. You should make careful consideration and only use regular expressions if you have a particular need.

PHP supports two different types of regular expressions: POSIX-extended and Perl-Compatible Regular Expressions (PCRE). The PCRE functions are more commonly used, are more powerful than the POSIX ones and faster as well

In a regular expression, most characters match only themselves. For instance, if you search for the regular expression “foo” in the string “only a fool does not use regular expressions” you get a match because “foo” occurs in that string. Some characters have a special meaning. For instance, the dollar sign ($) is used to match strings that end with the given pattern. Similarly, a caret (^) character at the beginning of a regular expression indicates that it must match the beginning of the string. Characters that match themselves are called literals while characters that have special meanings are called metacharacters. Read more »

Ubuntu 10.10 Maverick Meerkat Said To Be Radical

Ubuntu LogoThe new anticipated release of Ubuntu 10.10,  named “Maverick Meerkat” (currently in alpha2) is said to be radical, according to Marc Shuttleworth, chief of Canonical.

Canonical head Mark Shuttleworth mentioned on his blog that the upcoming Ubuntu version 10.10 will be focused on being social and fast. Shuttleworth says “The OS is getting faster and faster when it comes to boot times but the final push remains”. In the mean time, he said that the Netbook Edition of Ubuntu 10.10 will have a revamped UI and will be the fastest booting, fastest network OS for netbooks at this time. Canonical is the company that finances and oversees the Ubuntu project.

Ubuntu 10.10 is being called “Maverick Meerkat”. Meerkats are social creatures by nature and very family oriented and therefore has been adopted for this release. The Ubuntu project has been working very hard to become a viable and open source alternative to leading operating systems such as Mac OS X and  Windows 7.

Ubuntu is probably the most installed Linux distro currently, thanks to many different flavors (Ubuntu, Kubuntu, Xubuntu, Edubuntu, Ubuntu Studio and Ubuntu Netbook Edition). These variations include desktop and server versions including applicable applications and default settings. The last one is for netbooks and started with the amalgamations of Intel’s Moblin (Mobile Linux) into Ubuntu.

Ubuntu 10.10 promises to make everything faster and better than ever before, but ultimately will depend on how good Canonical is at keeping promises. Ubuntu has become a strong competitor and real alternative, and that is especially true for netbooks. For the average consumer, power users and production systems, the benefits come in the form of low cost, good stability and increased security.

Learn more about Ubuntu and the upcoming release.

Install And Use CouchDB With JSON And Map-Reduce

CouchDB is another offspring from the open-source, NoSQL, non-relational databases and is maintained under the Apache Foundation. It differs itself form the likes of MongoDB or Cassandra in that CouchDB is storing data in so called “documents” that are in JSON format, which can be hashes, lists, nested arrays and of course scalar values. This added complexity results in more powerful features, mainly to have a db that is not just a single key/value pair, but it comes at a price of speed reduction.

CouchDB can be a little bit of a pain to install, because it needs a few pre-requisites and they in turn have a few of their own quirks. This outline should help you get CouchDB with all it’s necessities installed. We’ve used MacOS, but you can substitute your OS where applicable.

The CouchDB source code and installer packages are downloadable here. As of this writing, version 0.11.2 is the latest stable version, with 1.0.1 just around the corner. You will also need Spider Monkey, Mozilla’s C implementation of JavaScript.

Installing SpiderMonkey

Once downloaded, extract the tarball and move into the sources folder:

tar -xzvf js-1.8.0-rc1.tar.gz

cd js/src

Read more »

Enable Gzip Compression In Apache And Optimize Page Load

HTML, CSS and Javascript compression is a simple and effective way to save bandwidth and speed up page load on your site. It’s often overlooked and yet simple to implement, just enable Gzip compression for the right document types and enhance your site’s user experience.

In Apache, we achieve this by enabling content encoding. When a user requests a file like http://www.msn.com/index.html, the browser communicates to a web server, and the conversation goes a something like this:

1. Browser: GET me /index.html
2. Server: Found indes.html, it’s 187KB! Response code is 200 (200 OK) , requested file is coming
3. Browser: 187KB, loading

The actual headers and protocols sent between the two are much more formal (monitor them with HTTPFox, Live HTTP Headers or others if you like.

Now, everything worked just fine in our little scenario, the browser got it’s requested file (index.html) of 187KB in size and probably also loaded include files such as javascript, css and a bunch of images. Especially on lower speed Internet connections, it took a few seconds for the page to load all files.

That’s where compression comes in. Html, javascript and css are plain text and are ideal candidates for compression, while images and videos usually underwent some compression algorithm when saved as jpg, png, avi or flv. Compressing those files would provide very little to no improvement in file size and add processing overhead to the web server. So we want to ensure we exclude those. Read more »

Page 2 of 6123456