Using Scripts to Automate SQL
Well I am getting my svk setup here to do some development on a few projects and I decided to try to get some automation in the setup. Seeing as I am currently hacking on Typo, I wanted someway for me to checkout the code from svk, setup my configs, and then put some test data into the databases.
Well using bash and some nice SQL I got a single script that will grab my database.yml config and then insert all my test data into my databases.
#!/bin/bash # Script to setup my Typo development env. cp /Users/eric/Development/Projects/\ typo-local/config/database.yml \config/database.yml echo "Done with Configs" mysql -u root --password=root typo_testing \So now for some sample SQL :
DROP TABLE IF EXISTS `settings`; CREATE TABLE IF NOT EXISTS `settings` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) default NULL, `value` varchar(255) default NULL, PRIMARY KEY (`id`) ) TYPE=InnoDB;So this SQL will drop the table settings and then insert the new one. This will make sure I have fresh data and works fine on all three databases (development, production, tests).
So now after I checkout and patch my next source for testing I just run
typo-setup.shAnd my databases and configs are ready to go, just fire up Webrick and go at it.
Later I will post on my new svk setup.
Eric
eXPlainPMT Guest Patch v0.0.0.0.1/2
I just finished working on a patch for Railfrog’s eXPlainPMT so we can have a read only guest access. It took me a bit of time but it is done…. by done I mean I have stopped to work on it today.
It is rather hackish and has 0 tests added but it provides the overall features needed. I had to touch the database, which sucks a bit but it is only one column so upgrades shouldn’t be too hard.
Well you can find it here at my dropbox
Eric
You might be a geek if...
…your phone’s startup screen display’s OOP code in it…
Powered by Ruby
Phone.startup.show_splash
Eric
Running Shell Commands in Ruby
One of the major benefits of unix is the quantity of many simple programs that one thing great. As a developer for unix, you must learn how to leverage these commands into your own scripts. Here is how to do this in Ruby.
Say you script wants to call on the unix command to view the amount of freespace on your disks.
df -h Filesystem Size Used Avail Capacity Mounted on /dev/disk0s3 37G 23G 14G 62% / devfs 110K 110K 0B 100% /dev fdesc 1.0K 1.0K 0B 100% /dev
To add this to Ruby all you need to do is to add a line of code (note the back-ticks):
disk_free = `df -h`
That takes the output from the command and puts it into a String. So an example script that will show the “df -h” output could be
#!/usr/bin/env ruby def disk_free diskfree = `df -h` puts diskfree end disk_free
How simple is that!
Now even though it would be easier to just use the real “df” command for this, you could easily write a Ruby script to call on other scripts and use all of Ruby’s powers to modify the output. That is how I made the Server Status Sidebar, calling “uptime” and regex to get the correct string I wanted.
Happy coding.
Eric
(Found this tip by using Safari)
Server Status Plugin
I just got a new sidebar plugin developed for Typo here. It shows the uptime and load average of the server it is running on.
It should work on any server that allows the “uptime” command to work. I have tested it on OSX(Darwin) and Debian 3.1 so far and it works on both.
I am going to hold on to it for a bit to test it out some more but will add the patch to Typo soon. (Main stopper is my diff isn’t coming out right.)
Anyways see it in action over here on my sidebar and if you want to grab the copy, it is at my dropbox. The diff comes from REV 657, even though it doesn’t say.
This plugin, plugin code, and all it’s goodies will be released under the MIT License (same as Typo).
Eric
