<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>[ themattreid ] &#187; Scripts</title>
	<atom:link href="http://themattreid.com/wordpress/category/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://themattreid.com/wordpress</link>
	<description>MySQL DBA &#124; Linux&#039;er</description>
	<lastBuildDate>Sat, 07 Jan 2012 00:22:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL Load Testing Framework &#8211; initial release</title>
		<link>http://themattreid.com/wordpress/2011/05/19/mysql-load-testing-framework-initial-release/</link>
		<comments>http://themattreid.com/wordpress/2011/05/19/mysql-load-testing-framework-initial-release/#comments</comments>
		<pubDate>Thu, 19 May 2011 17:52:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[loadtesting]]></category>
		<category><![CDATA[mysql mysql server]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[sysbench]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=487</guid>
		<description><![CDATA[<p>It seems that everyone loves load testing these days. Problem is that everyone is using their own quick scripts, simple or complex, to drive their tests without the ability for other DBAs to duplicate those tests. Let&#8217;s say I write a great test and share my results and graphs on the blog &#8211; you want to run the same tests to see how your new DB servers compare in performance: this framework allows you to &#8230; <a href="http://themattreid.com/wordpress/2011/05/19/mysql-load-testing-framework-initial-release/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>It seems that everyone loves load testing these days. Problem is that everyone is using their own quick scripts, simple or complex, to drive their tests without the ability for other DBAs to duplicate those tests. Let&#8217;s say I write a great test and share my results and graphs on the blog &#8211; you want to run the same tests to see how your new DB servers compare in performance: this framework allows you to do that without duplicating any work or writing code. This is a basic release that will get the ball rolling. I&#8217;ve included some sample tests in the README file, so give them a try.</p>
<p>This codebase offers a user friendly framework for creating and visualizing MySQL database load test jobs. It is based around Sysbench, which is generally considered the industry standard load test application. The framework allows you to do the following:</p>
<ul> standardize your tests without requiring you to write one-off bash scripts to handle looping and iteration commands.<br />
graphing output via Highcharts and Sparklines (coming in the next release in a week)<br />
CSV test result output for easy import to other data visualization systems or import into a SQL database<br />
customize your iterations via ability to watch an unlimited number of MySQL global status variables<br />
customize your iterations via ability to alter MySQL global variables between iterations<br />
run arbitrary SQL commands between each iteration<br />
allows you to control the caches between iterations<br />
set custom default values and create configuration templates for easy repeatability and portability of your tests<br />
extensible code base: written purely in Python 2.6</ul>
<p>Download it now: <a href="http://code.google.com/p/quadrant-framework/" target="_blank">http://code.google.com/p/quadrant-framework/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2011/05/19/mysql-load-testing-framework-initial-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun with Bash: aliases make your live easier&#8230; share your favorites</title>
		<link>http://themattreid.com/wordpress/2011/02/09/fun-with-bash-aliases-make-your-live-easier-share-your-favorites/</link>
		<comments>http://themattreid.com/wordpress/2011/02/09/fun-with-bash-aliases-make-your-live-easier-share-your-favorites/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 04:18:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[bsd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=469</guid>
		<description><![CDATA[<p>I&#8217;ve always been a big fan of having a customized .bashrc file. The one I distribute to all of my servers has aliases for quick commands to save me time on the command line, functions that get work done when aliases are too simplistic, reporting for the server for each cli login, and of course a formatted and colored prompt (for terms that support colors). I also change certain aspects and commands based on the &#8230; <a href="http://themattreid.com/wordpress/2011/02/09/fun-with-bash-aliases-make-your-live-easier-share-your-favorites/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always been a big fan of having a customized .bashrc file. The one I distribute to all of my servers has aliases for quick commands to save me time on the command line, functions that get work done when aliases are too simplistic, reporting for the server for each cli login, and of course a formatted and colored prompt (for terms that support colors). I also change certain aspects and commands based on the operating system since I&#8217;m not always on a redhat box or linux at all. <a href="http://pastebin.com/sVw8guUE">Here&#8217;s my bashrc file</a> &#8211; maybe you have some fun additions that you&#8217;d like to share. What saves you time on the command line? </p>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2011/02/09/fun-with-bash-aliases-make-your-live-easier-share-your-favorites/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Python for Automation: using pdsh for a menu-driven command execution environment</title>
		<link>http://themattreid.com/wordpress/2011/02/04/python-for-automation-using-pdsh-for-a-menu-driven-command-execution-environment/</link>
		<comments>http://themattreid.com/wordpress/2011/02/04/python-for-automation-using-pdsh-for-a-menu-driven-command-execution-environment/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 22:15:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bsd]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pdsh]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=447</guid>
		<description><![CDATA[<p>I&#8217;ve been playing around with some quick system automation scripts that are handy to use when you don&#8217;t want / need to setup a chef or puppet action. I like to keep all of my hostnames and login details in a MySQL database (a cmdb actually) but for this example we&#8217;ll just use a couple of nested lists. This script executes commands in parallel across the hosts you choose in the menu system via the &#8230; <a href="http://themattreid.com/wordpress/2011/02/04/python-for-automation-using-pdsh-for-a-menu-driven-command-execution-environment/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with some quick system automation scripts that are handy to use when you don&#8217;t want / need to setup a chef or puppet action. I like to keep all of my hostnames and login details in a MySQL database (a cmdb actually) but for this example we&#8217;ll just use a couple of nested lists. This script executes commands in parallel across the hosts you choose in the menu system via the &#8220;pdsh&#8221; command, so make sure you have that installed before running. Alternately you can change the command call to use ssh instead of pdsh for a serialized execution, but that&#8217;s not as fun or fast. With some customizations here and there you can expand this to operate parallelized jobs for simplifying daily work in database administration, usage reporting, log file parsing, or other system automation as you see fit. Here&#8217;s the code. Comments welcome as always!</p>
<pre name="code" class="python">
#!/usr/bin/env python
## NAME: menu_parallel_execution.py
## DATE: 2011-02-04
## AUTHOR: Matt Reid
## WEBSITE: http://kontrollsoft.com
## EMAIL: mreid@kontrollsoft.com
## LICENSE: BSD http://www.opensource.org/licenses/bsd-license.php

import commands
import sys
import os
import operator

ver = sys.version.split(' ')[0].split(".")
major=ver[:1]
minor=ver[1:2]
version="%s.%s"%(major[0],minor[0])
if version in ('2.4','2.3','2.2','2.1','2.0'):
	pyver = "old"
else:
	from subprocess import Popen, PIPE, STDOUT, call
	pyver = "new"

def main():
        #This section of host definitions could be replaced by a database
        #call if you are storing your hosts in that manner, but we'll keep
        #this script simple for the time being.
	dc0 = [
		["host0-0","10.0.0.1","ssh-username"],
		["host0-1","10.0.0.2","ss-username"]]

	dc1 = [
		["host1-0","10.1.0.1","ssh-username"],
		["host1-1","10.1.0.2","ss-username"]]

	dc2 = [
		["host2-0","10.2.0.1","ssh-username"],
		["host2-1","10.2.0.2","ss-username"]]

	print '''[1] Datacenter-1
[2] Datacenter-2
[3] Datacenter-3
'''
	dc = int(raw_input("Datacenter ID: "))
	if dc == 1:
		hosts = dc0
	elif dc == 2:
		hosts = dc1
	elif dc == 3:
		hosts = dc3

	nodes = []
	stay = True
	while stay == True:
		i = 0
		nest = sorted(hosts, key=operator.itemgetter(0))
		for x in range(len(nest)):
			print "[%i] %s | %s"%(i,nest[i][1],nest[i][0])
			i+=1

		print "\nSelect node to add to execution list"
		ch = int(raw_input("ID: "))
		xx = [nest[ch][1],nest[ch][2]]
		nodes.append(xx)
		s = str(raw_input("\nAdd another node? [Y/n] "))
		if s == "n" or s == "N":
			stay = False

	if(pyver == "new"):
		addrs = ""
		for node in nodes:
			address = node[1]+"@"+node[0]+","
			address = address.rstrip("\n")
			addrs = addrs+address

		addrs = addrs.strip(",")
		cmd = str(raw_input("\nEnter the command to execute: "))				

		try:
			c = "pdsh -w %s %s"%(addrs,cmd)
			print "Executing: %s"%(c)
			call(c,shell=True)
		except:
			print "Failed to execute pdsh command: %s"%(c)
			sys.exit(1)

		sys.exit(0)

	if(pyver == "old"):
		print "Please upgrade to Python 2.6+"
		sys.exit(1)

## START
if __name__ == "__main__":
	try:
		retval = main()
	except (KeyboardInterrupt, SystemExit):
		sys.exit(1)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2011/02/04/python-for-automation-using-pdsh-for-a-menu-driven-command-execution-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Python: a job queue with threading</title>
		<link>http://themattreid.com/wordpress/2011/01/20/simple-python-a-job-queue-with-threading/</link>
		<comments>http://themattreid.com/wordpress/2011/01/20/simple-python-a-job-queue-with-threading/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 02:18:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[queue]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=436</guid>
		<description><![CDATA[<p>Every so often you need to use a queue to manage operations in an application. Python makes this very simple. Python also, as I&#8217;ve written about before, makes threading very easy to work with. So in this quick program I&#8217;ll describe via comments, how to make a simple queue where each job is processed by a thread. Integrating this code to read jobs from a mysql database would be trivial as well; simply replace the &#8230; <a href="http://themattreid.com/wordpress/2011/01/20/simple-python-a-job-queue-with-threading/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>Every so often you need to use a queue to manage operations in an application. Python makes this very simple. Python also, as I&#8217;ve written about before, makes threading very easy to work with. So in this quick program I&#8217;ll describe via comments, how to make a simple queue where each job is processed by a thread. Integrating this code to read jobs from a mysql database would be trivial as well; simply replace the &#8220;jobs = [..." code with a database call to a row select query.</p>
<pre name="code" class="python">
#!/usr/bin/env python
## DATE: 2011-01-20
## FILE: queue.py
## AUTHOR: Matt Reid
## WEBSITE: http://themattreid.com
from Queue import *
from threading import Thread, Lock

'''this function will process the items in the queue, in serial'''
def processor():
    if queue.empty() == True:
        print "the Queue is empty!"
        sys.exit(1)
    try:
        job = queue.get()
        print "I'm operating on job item: %s"%(job)
        queue.task_done()
    except:
        print "Failed to operate on job"

'''set variables'''
queue = Queue()
threads = 4

'''a list of job items. you would want this to be more advanced,
like reading from a file or database'''
jobs = [ "job1", "job2", "job3" ]

&#8221;&#8217;iterate over jobs and put each into the queue in sequence&#8221;&#8217;
for job in jobs:
     print &#8220;inserting job into the queue: %s&#8221;%(job)
     queue.put(job)

&#8221;&#8217;start some threads, each one will process one job from the queue&#8221;&#8217;
for i in range(threads):
     th = Thread(target=processor)
     th.setDaemon(True)
     th.start()

&#8221;&#8217;wait until all jobs are processed before quitting&#8221;&#8217;
queue.join()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2011/01/20/simple-python-a-job-queue-with-threading/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A simple load test script in Python</title>
		<link>http://themattreid.com/wordpress/2010/11/03/a-simple-load-test-script-in-python/</link>
		<comments>http://themattreid.com/wordpress/2010/11/03/a-simple-load-test-script-in-python/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 20:14:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[load test]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=375</guid>
		<description><![CDATA[<p>Lately I&#8217;ve had to do some environment load testing so I wrote this quick script. It can be modified as needed but the basic idea is that it spawns $x threads (&#8211;threads) and then sends two connections (or however many you want with &#8211;per-connection=) per thread to the URL (&#8211;url=). You can have it wait a configurable time between connections as well (&#8211;wait=).</p>
<p>The url is appended with a 32 character randomized string so that &#8230; <a href="http://themattreid.com/wordpress/2010/11/03/a-simple-load-test-script-in-python/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve had to do some environment load testing so I wrote this quick script. It can be modified as needed but the basic idea is that it spawns $x threads (&#8211;threads) and then sends two connections (or however many you want with &#8211;per-connection=) per thread to the URL (&#8211;url=). You can have it wait a configurable time between connections as well (&#8211;wait=).</p>
<p>The url is appended with a 32 character randomized string so that any database/caching on the backend of the site isn&#8217;t serving data from a warm cache. You can hunt down the string length for 32 and change it to whatever you want. Feel free to change and use as needed, just keep my info at top. </p>
<pre name="code" class="python">
#!/usr/bin/python
################################################################################
## DATE: 2010-10-26
## AUTHOR: Matt Reid
## MAIL: mreid@kontrollsoft.com
## SITE: http://kontrollsoft.com
## LICENSE: BSD http://www.opensource.org/licenses/bsd-license.php
################################################################################

from __future__ import division
import threading
import sys
import urllib2
import select
import random
import string
import getopt
import time

class threader(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        global url
        global per
        global u
        for i in range(per):
            if wait > 0:
                time.sleep(wait)
            str = randstr(32)
            # IMPORTANT: this is where we append the search string to the main URL
            # you might need to change this for your site.
            url = "%s/search/%s"%(u,str)
            print "polling url: %s"%(url)
            urllib2.urlopen(url)

def randstr(length):
    global url
    twoletters = [c+d for c in string.letters for d in string.letters]
    r = random.random
    n = len(twoletters)
    l2 = length//2
    lst = [None] * l2
    for i in xrange(l2):
        lst[i] = twoletters[int(r() * n)]
        if length &#038; 1:
            lst.append(random.choice(string.letters))

    return "".join(lst)

def init_thread():
    backgrounds = []
    for thread in range(threads):
        print "Spawning thread: %s"%(thread)
        background = threader()
        background.start()
        backgrounds.append(background)
    for background in backgrounds:
        background.join()

def print_help():
    print '''loader.py - URL load test script
==================================================
Date: 2010-08-26
Website: http://themattreid.com
Author: Matt Reid
Email: themattreid@gmail.com
License: new BSD license
==================================================
Use the following flags to change default behavior

   Option                 Description
   --url=                 URL to test
   --per-connection=      Number of sequential reqests per connection (default 2)
   --threads=             Number of threads for url connections (default 50)
   --wait=                Time to wait in-between requests
   --help                 Print this message

   -u                     Same as --url
   -p                     Same as --per-connection
   -t                     Same as --threads
   -w                     Same as --wait
   -h                     Same as --help
   '''

def main():
    init_thread()
    sys.exit(0)

if __name__ == "__main__":
    global threads #num threads/connections to open
    global u #url to hit
    global per #per connection url hits
    try:
        options, remainder = getopt.getopt(
            sys.argv[1:], 'ptuw', ['per-connection=',
                                   'threads=',
                                   'url=',
                                   'wait=',
                                   'help'])
    except getopt.GetoptError, err:
        print str(err)
        sys.exit(2)

    for opt, arg in options:
        if opt in ('--per-connection'):
            per = int(arg)
        elif opt in ('--threads'):
            threads = int(arg)
        elif opt in ('--url'):
            u = arg
        elif opt in ('--wait'):
            wait = int(arg)
        elif opt in ('--help'):
            print_help()
            sys.exit(2)

    try:
        threads
    except NameError:
        print "No thread quantity specified."
        print_help()
        sys.exit(2)
    try:
        per
    except NameError:
        per = 2
    try:
        u
    except NameError:
        print "No URL Specified"
        print_help()
        sys.exit(2)
    try:
        wait
    except NameError:
        wait=0

    main()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2010/11/03/a-simple-load-test-script-in-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Easy Python: multi-threading MySQL queries</title>
		<link>http://themattreid.com/wordpress/2010/08/30/easy-python-threading-mysql-connections/</link>
		<comments>http://themattreid.com/wordpress/2010/08/30/easy-python-threading-mysql-connections/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 21:04:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=356</guid>
		<description><![CDATA[<p>There are many times when writing an application that single threaded database operations are simply too slow. In these cases it&#8217;s a matter of course that you&#8217;ll use multi-threading or forking to spawn secondary processes to handle the database actions. In this simple example for Python multi-threading you&#8217;ll see the how simple it is to improve the performance of your python app.</p>
<pre name="code" class="py">#!/usr/bin/python
## DATE: 2010-08-30
## AUTHOR: Matt Reid
## WEBSITE: http://themattreid.com
## LICENSE: &#8230; <a href="http://themattreid.com/wordpress/2010/08/30/easy-python-threading-mysql-connections/" class="read_more">Read the rest</a></pre>]]></description>
			<content:encoded><![CDATA[<p>There are many times when writing an application that single threaded database operations are simply too slow. In these cases it&#8217;s a matter of course that you&#8217;ll use multi-threading or forking to spawn secondary processes to handle the database actions. In this simple example for Python multi-threading you&#8217;ll see the how simple it is to improve the performance of your python app.</p>
<pre name="code" class="py">#!/usr/bin/python
## DATE: 2010-08-30
## AUTHOR: Matt Reid
## WEBSITE: http://themattreid.com
## LICENSE: BSD http://www.opensource.org/licenses/bsd-license.php
## Copyright 2010-present Matt Reid

from __future__ import division
from socket import gethostname;
import threading
import sys
import os
import MySQLdb

class threader(threading.Thread):
    def __init__(self,method):
        threading.Thread.__init__(self)
        self.tx =
        self.method = method
    def run(self):
        run_insert()

def run_insert():
    sql = "INSERT INTO table (`id`,`A`,`B`,`C`) VALUES (NULL,'0','0','0');")
        try:
            cursor.execute(sql)
            db.commit()
        except:
            print "insert failed"

def init_thread(): backgrounds = []
    for db in connections:
       logger("Spawning thread: %s"%(db),"d")
       quant = tx / THREADS
       background = threader(method,quant,db)        
       background.start()
       backgrounds.append(background)
    for background in backgrounds:
       background.join()

def main():
    try:
        init_thread()
    except:
        print "failed to initiate threads"

    sys.exit(0)

if __name__ == "__main__":
    mysql_host = "localhost" #default localhost
    mysql_pass = "pass" #default dbbench
    mysql_user = "user" #default dbbench
    mysql_port = 3306 #default 3306
    mysql_db = "schema" #default dbbench
    threads = 4 #must be INT not STR #create connection pool

    connections = []
    for thread in range(THREADS):
      try:
       connections.append(MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_pass, db=mysql_db, port=mysql_port))
      except MySQLdb.Error, e:
       print "Error %d: %s"%(e.args[0], e.args[1])
       sys.exit (1)

    main()
    </pre>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2010/08/30/easy-python-threading-mysql-connections/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Easy Python: display LVM details in XML</title>
		<link>http://themattreid.com/wordpress/2010/08/15/easy-python-display-lvm-details-in-xml/</link>
		<comments>http://themattreid.com/wordpress/2010/08/15/easy-python-display-lvm-details-in-xml/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 22:35:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=338</guid>
		<description><![CDATA[<p>If you need to work with LVM in your scripts but haven&#8217;t found a good method to access details about Logical Volume Groups, here&#8217;s a simple Python script that will print the details about any volumes on your system. This could be useful for writing a partition check script for your MySQL data directory (if you&#8217;re not using a standard monitoring system like Nagios). </p>
<pre name="code" class="py">
import sys
import os
import commands
import subprocess
import select

def &#8230; <a href="http://themattreid.com/wordpress/2010/08/15/easy-python-display-lvm-details-in-xml/" class="read_more">Read the rest</a></pre>]]></description>
			<content:encoded><![CDATA[<p>If you need to work with LVM in your scripts but haven&#8217;t found a good method to access details about Logical Volume Groups, here&#8217;s a simple Python script that will print the details about any volumes on your system. This could be useful for writing a partition check script for your MySQL data directory (if you&#8217;re not using a standard monitoring system like Nagios). </p>
<pre name="code" class="py">
import sys
import os
import commands
import subprocess
import select

def lvm():
    print ""
    LVM_PATH = "/sbin"
    LVM_BIN = os.path.join(LVM_PATH, 'lvm')
    argv = list()
    argv.append(LVM_BIN)
    argv.append("lvs")
    argv.append("--nosuffix")
    argv.append("--noheadings")
    argv.append("--units")
    argv.append("b")
    argv.append("--separator")
    argv.append(";")
    argv.append("-o")
    argv.append("lv_name,vg_name,lv_size")

    process = subprocess.Popen(argv, stdout=subprocess.PIPE)
    output = ""
    out = process.stdout.readline()
    output += out
    lines = output.splitlines()
    for line in lines:
        line = line.strip()
        words = line.split(";")

        lvname = words[0].strip()
        vgname = words[1].strip()
        lv_size = int(words[2])
        print '''
    %s
    %s
    %s
  '''%(lvname, vgname, lv_size)

    print ""

lvm()</pre>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2010/08/15/easy-python-display-lvm-details-in-xml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easy MySQL: how to backup databases to a remote machine</title>
		<link>http://themattreid.com/wordpress/2010/08/13/easy-mysql-how-to-backup-databases-to-a-remote-machine/</link>
		<comments>http://themattreid.com/wordpress/2010/08/13/easy-mysql-how-to-backup-databases-to-a-remote-machine/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 21:27:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Backups]]></category>
		<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=335</guid>
		<description><![CDATA[<p>Here&#8217;s a simple answer to a simple question. &#8220;How do I run a backup of MySQL to another machine without writing to the local server&#8217;s filesystem?&#8221; &#8211; this is especially useful if you are running out of space on the local server and cannot write a temporary file to the filesystem during backups. </p>
<p>Method one &#8211; this writes a remote file.<br />
<code>mysqldump [options] [db_name&#124;--all-databases]&#124; gzip -c &#124; ssh user@host.com "cat /path/to/new/file.sql.gz"</code></p>
<p>Method two &#8211; this &#8230; <a href="http://themattreid.com/wordpress/2010/08/13/easy-mysql-how-to-backup-databases-to-a-remote-machine/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a simple answer to a simple question. &#8220;How do I run a backup of MySQL to another machine without writing to the local server&#8217;s filesystem?&#8221; &#8211; this is especially useful if you are running out of space on the local server and cannot write a temporary file to the filesystem during backups. </p>
<p>Method one &#8211; this writes a remote file.<br />
<code>mysqldump [options] [db_name|--all-databases]| gzip -c | ssh user@host.com "cat > /path/to/new/file.sql.gz"</code></p>
<p>Method two &#8211; this writes directly into a remote mysql server<br />
<code>mysqldump [options] [db_name|--all-databases]| mysql --host=[remote host] –user=root –password=[pass] [db_name]</code></p>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2010/08/13/easy-mysql-how-to-backup-databases-to-a-remote-machine/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Easy Python: MySQL connection and iteration</title>
		<link>http://themattreid.com/wordpress/2010/08/10/simple-python-mysql-connection-and-iteration/</link>
		<comments>http://themattreid.com/wordpress/2010/08/10/simple-python-mysql-connection-and-iteration/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 19:25:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=330</guid>
		<description><![CDATA[<p>If you&#8217;ve been looking for a simple python script to use with MySQL that you can use to expand upon for your next project, check this one out. It has error handling for the connection, error handling for the sql call, and loop iteration for the rows returned. </p>
<pre name="code" class="py">
#!/usr/bin/python
import sys
import MySQLdb

my_host = "localhost"
my_user = "user"
my_pass = "password"
my_db = "test"

try:
    db = MySQLdb.connect(host=my_host, user=my_user, passwd=my_pass, db=my_db)
except MySQLdb.Error, e:
     &#8230; <a href="http://themattreid.com/wordpress/2010/08/10/simple-python-mysql-connection-and-iteration/" class="read_more">Read the rest</a></pre>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve been looking for a simple python script to use with MySQL that you can use to expand upon for your next project, check this one out. It has error handling for the connection, error handling for the sql call, and loop iteration for the rows returned. </p>
<pre name="code" class="py">
#!/usr/bin/python
import sys
import MySQLdb

my_host = "localhost"
my_user = "user"
my_pass = "password"
my_db = "test"

try:
    db = MySQLdb.connect(host=my_host, user=my_user, passwd=my_pass, db=my_db)
except MySQLdb.Error, e:
     print "Error %d: %s" % (e.args[0], e.args[1])
     sys.exit (1)

cursor = db.cursor()
sql = "select column1, column2 from table";
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
    column1 = row[0]
    column2 = row[1]
    print "column1: %s, column2: %s"%(column1,column2)

db.close()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2010/08/10/simple-python-mysql-connection-and-iteration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: rotate wordpress posts into headline/feature status</title>
		<link>http://themattreid.com/wordpress/2010/08/07/how-to-rotate-wordpress-posts-into-headlinefeature-status/</link>
		<comments>http://themattreid.com/wordpress/2010/08/07/how-to-rotate-wordpress-posts-into-headlinefeature-status/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 00:16:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL Server]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=323</guid>
		<description><![CDATA[<p>If you&#8217;re using the new <a href="http://www.themelab.com/2008/08/26/arthemia-wordpress-theme-review/" target="_blank">Arthemia theme</a> for WordPress you might notice that there are two areas of the theme that can have articles promoted to; namely Headline and Featured sections. This is controlled by category association. Basically you have a post and if you want it in the Headline area of the theme you attach the category &#8220;headline&#8221; to it, similarly for the featured section. Now, let&#8217;s say you don&#8217;t want to manually change &#8230; <a href="http://themattreid.com/wordpress/2010/08/07/how-to-rotate-wordpress-posts-into-headlinefeature-status/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using the new <a href="http://www.themelab.com/2008/08/26/arthemia-wordpress-theme-review/" target="_blank">Arthemia theme</a> for WordPress you might notice that there are two areas of the theme that can have articles promoted to; namely Headline and Featured sections. This is controlled by category association. Basically you have a post and if you want it in the Headline area of the theme you attach the category &#8220;headline&#8221; to it, similarly for the featured section. Now, let&#8217;s say you don&#8217;t want to manually change this all the time since it can be time consuming to promote posts to those categories if you want rotating content.</p>
<p>Here&#8217;s a simple solution. In this bash script I connect to MySQL and remove the current associations from posts and then randomly choose posts to be promoted to the Headline and Featured categories. This can be modified for other ideas you might have involving categories/posts/randomized associations in WordPress. </p>
<p>The queries contain IDs for the Headline and Featured categories. In my installation, which will be different than yours, has the Headline category as ID=&#8217;103&#8242; and Featured as ID=&#8217;104&#8242; &#8211; replace as needed. I&#8217;m also doing some matching (see the WHERE sections) so that I don&#8217;t promote posts with certain IDs that are specific to the site for this script. You&#8217;ll want to customize the queries as needed for your site. You can find the script here: <a href="http://pastebin.com/1QqiM5rh">http://pastebin.com/1QqiM5rh</a></p>
]]></content:encoded>
			<wfw:commentRss>http://themattreid.com/wordpress/2010/08/07/how-to-rotate-wordpress-posts-into-headlinefeature-status/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

