<?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>PlanetMysql.ru - информация о СУБД MySQL &#187; bash</title>
	<atom:link href="http://planetmysql.ru/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetmysql.ru</link>
	<description>Блог о самой популярной СУБД MySQL</description>
	<lastBuildDate>Sat, 04 Feb 2012 15:42:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Fun with Bash: aliases make your live easier&#8230; share your favorites</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/ZGDuXjwThXs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-bash-aliases-make-your-live-easier-share-your-favorites</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/ZGDuXjwThXs/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 04:19:04 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[BSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=469</guid>
		<description><![CDATA[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. Here&#8217;s my bashrc file &#8211; maybe you have some fun additions that you&#8217;d like to share. What saves you time on the command line?]]></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>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/ZGDuXjwThXs" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27276&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27276&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/02/10/fun-with-bash-aliases-make-your-live-easier-share-your-favorites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Bash] Performing array intersection with Bash</title>
		<link>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bash-performing-array-intersection-with-bash</link>
		<comments>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 01:15:51 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=224</guid>
		<description><![CDATA[I am currently working on a project to deploy new website builds to a
small number of servers.  I needed something simple and reliable that could
be built in a very short period of time.  I decided to whip something up in
bash with the intent of refining it in Python later.
As I began to write this code, I realized that it probably would have been
quicker to do it in Python from the start.  I decided to stick with bash as
somewhat of an academic exercise.  The vast majority of these deployment
scripts were trivial; check the code out of git, create a manifest, package
it up, spew it to the servers, etc, etc.  The problem came during the last
step.  We decided to use a symlink to point to the active build out of a
number of builds that could be available on the server at any given time.
Since all of our servers should be running the exact same version of the
build, it makes sense that I should only allow a user of my deployment
scripts to link a build which exists on all servers.  But how do you
accomplish this in bash?
In most other languages, you have access to numerous array helping
functions that allow you to perform intersects, uniqs, and merges.  My goal
was to do the same thing in bash without forking out to any external
binary.  So how do you ensure that a particular thing exists on N number of
servers?  Here it is:
function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &#38;&#38; return 1
 [ -z "${ENTRY}" ] &#38;&#38; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &#38;&#38; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done
Let me take a moment to explain the code above:

 In order to check for array intersection, you need an in_array()
function

The first argument as the &#8220;needle&#8221; and the second is the
&#8220;haystack&#8221;
We verify that both parameters were passed
We simply loop through the haystack checking for the needle
If we find it, return success.  Otherwise, eventually return
false


We need to loop through each server eventually, but we&#8217;ll start with
the first one

Run an SSH command to get a listing of builds
Populate an array ($CURRENT) with the builds that were found


Since the first server has no previous server to compare with, so we
just copy it to $MASTER


We then loop to the 2nd server, and put the result of getting builds
into $CURRENT

Now that we have the first server&#8217;s builds in $MASTER, we perform an
intersect with $CURRENT
We realize the need for an $INTERSECT array to hold the intersections
found above
$INTERSECT becomes $MASTER since it only contains similar builds from
the 1st and 2nd server


Looping to the 3rd server, we get the builds and put them in $CURRENT

Since $MASTER contains only the similar builds thus far, we again
compare it with $CURRENT
The intersect can now be used to compare against builds on the 4th
server, and so on


Once you finish looping through all servers, your $MASTER should
contain only similar builds

There are a few guides out there which show you how to do this via
forking, but I thought someone may appreciate the elegance of using 100%
bash to accomplish this.  I hope this helps someone else out there!]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a project to deploy new website builds to a<br />
small number of servers.  I needed something simple and reliable that could<br />
be built in a very short period of time.  I decided to whip something up in<br />
bash with the intent of refining it in Python later.</p>
<p>As I began to write this code, I realized that it probably would have been<br />
quicker to do it in Python from the start.  I decided to stick with bash as<br />
somewhat of an academic exercise.  The vast majority of these deployment<br />
scripts were trivial; check the code out of git, create a manifest, package<br />
it up, spew it to the servers, etc, etc.  The problem came during the last<br />
step.  We decided to use a symlink to point to the active build out of a<br />
number of builds that could be available on the server at any given time.<br />
Since all of our servers should be running the exact same version of the<br />
build, it makes sense that I should only allow a user of my deployment<br />
scripts to link a build which exists on all servers.  But how do you<br />
accomplish this in bash?</p>
<p>In most other languages, you have access to numerous array helping<br />
functions that allow you to perform intersects, uniqs, and merges.  My goal<br />
was to do the same thing in bash without forking out to any external<br />
binary.  So how do you ensure that a particular thing exists on N number of<br />
servers?  Here it is:</p>
<pre lang="bash">function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &amp;&amp; return 1
 [ -z "${ENTRY}" ] &amp;&amp; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &amp;&amp; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done</pre>
<p>Let me take a moment to explain the code above:</p>
<ul>
<li> In order to check for array intersection, you need an in_array()<br />
function</p>
<ul>
<li>The first argument as the &#8220;needle&#8221; and the second is the<br />
&#8220;haystack&#8221;</li>
<li>We verify that both parameters were passed</li>
<li>We simply loop through the haystack checking for the needle</li>
<li>If we find it, return success.  Otherwise, eventually return<br />
false</li>
</ul>
</li>
<li>We need to loop through each server eventually, but we&#8217;ll start with<br />
the first one</p>
<ul>
<li>Run an SSH command to get a listing of builds</li>
<li>Populate an array ($CURRENT) with the builds that were found</li>
</ul>
<ul>
<li>Since the first server has no previous server to compare with, so we<br />
just copy it to $MASTER</li>
</ul>
</li>
<li>We then loop to the 2nd server, and put the result of getting builds<br />
into $CURRENT</p>
<ul>
<li>Now that we have the first server&#8217;s builds in $MASTER, we perform an<br />
intersect with $CURRENT</li>
<li>We realize the need for an $INTERSECT array to hold the intersections<br />
found above</li>
<li>$INTERSECT becomes $MASTER since it only contains similar builds from<br />
the 1st and 2nd server</li>
</ul>
</li>
<li>Looping to the 3rd server, we get the builds and put them in $CURRENT
<ul>
<li>Since $MASTER contains only the similar builds thus far, we again<br />
compare it with $CURRENT</li>
<li>The intersect can now be used to compare against builds on the 4th<br />
server, and so on</li>
</ul>
</li>
<li>Once you finish looping through all servers, your $MASTER should<br />
contain only similar builds</li>
</ul>
<p>There are a few guides out there which show you how to do this via<br />
forking, but I thought someone may appreciate the elegance of using 100%<br />
bash to accomplish this.  I hope this helps someone else out there!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/10/26/bash-performing-array-intersection-with-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Bash] Performing array intersection with Bash</title>
		<link>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bash-performing-array-intersection-with-bash</link>
		<comments>http://crazytoon.com/2010/10/25/bash-performing-array-intersection-with-bash/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 01:15:51 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux Apache MySQL PHP]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>

		<guid isPermaLink="false">http://crazytoon.com/?p=224</guid>
		<description><![CDATA[I am currently working on a project to deploy new website builds to a
small number of servers.  I needed something simple and reliable that could
be built in a very short period of time.  I decided to whip something up in
bash with the intent of refining it in Python later.
As I began to write this code, I realized that it probably would have been
quicker to do it in Python from the start.  I decided to stick with bash as
somewhat of an academic exercise.  The vast majority of these deployment
scripts were trivial; check the code out of git, create a manifest, package
it up, spew it to the servers, etc, etc.  The problem came during the last
step.  We decided to use a symlink to point to the active build out of a
number of builds that could be available on the server at any given time.
Since all of our servers should be running the exact same version of the
build, it makes sense that I should only allow a user of my deployment
scripts to link a build which exists on all servers.  But how do you
accomplish this in bash?
In most other languages, you have access to numerous array helping
functions that allow you to perform intersects, uniqs, and merges.  My goal
was to do the same thing in bash without forking out to any external
binary.  So how do you ensure that a particular thing exists on N number of
servers?  Here it is:
function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &#38;&#38; return 1
 [ -z "${ENTRY}" ] &#38;&#38; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &#38;&#38; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done
Let me take a moment to explain the code above:

 In order to check for array intersection, you need an in_array()
function

The first argument as the &#8220;needle&#8221; and the second is the
&#8220;haystack&#8221;
We verify that both parameters were passed
We simply loop through the haystack checking for the needle
If we find it, return success.  Otherwise, eventually return
false


We need to loop through each server eventually, but we&#8217;ll start with
the first one

Run an SSH command to get a listing of builds
Populate an array ($CURRENT) with the builds that were found


Since the first server has no previous server to compare with, so we
just copy it to $MASTER


We then loop to the 2nd server, and put the result of getting builds
into $CURRENT

Now that we have the first server&#8217;s builds in $MASTER, we perform an
intersect with $CURRENT
We realize the need for an $INTERSECT array to hold the intersections
found above
$INTERSECT becomes $MASTER since it only contains similar builds from
the 1st and 2nd server


Looping to the 3rd server, we get the builds and put them in $CURRENT

Since $MASTER contains only the similar builds thus far, we again
compare it with $CURRENT
The intersect can now be used to compare against builds on the 4th
server, and so on


Once you finish looping through all servers, your $MASTER should
contain only similar builds

There are a few guides out there which show you how to do this via
forking, but I thought someone may appreciate the elegance of using 100%
bash to accomplish this.  I hope this helps someone else out there!]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a project to deploy new website builds to a<br />
small number of servers.  I needed something simple and reliable that could<br />
be built in a very short period of time.  I decided to whip something up in<br />
bash with the intent of refining it in Python later.</p>
<p>As I began to write this code, I realized that it probably would have been<br />
quicker to do it in Python from the start.  I decided to stick with bash as<br />
somewhat of an academic exercise.  The vast majority of these deployment<br />
scripts were trivial; check the code out of git, create a manifest, package<br />
it up, spew it to the servers, etc, etc.  The problem came during the last<br />
step.  We decided to use a symlink to point to the active build out of a<br />
number of builds that could be available on the server at any given time.<br />
Since all of our servers should be running the exact same version of the<br />
build, it makes sense that I should only allow a user of my deployment<br />
scripts to link a build which exists on all servers.  But how do you<br />
accomplish this in bash?</p>
<p>In most other languages, you have access to numerous array helping<br />
functions that allow you to perform intersects, uniqs, and merges.  My goal<br />
was to do the same thing in bash without forking out to any external<br />
binary.  So how do you ensure that a particular thing exists on N number of<br />
servers?  Here it is:</p>
<pre lang="bash">function in_array() {
 local x
 ENTRY=$1
 shift 1
 ARRAY=( "$@" )
 [ -z "${ARRAY}" ] &amp;&amp; return 1
 [ -z "${ENTRY}" ] &amp;&amp; return 1
 for x in ${ARRAY[@]}; do
   [ "${x}" == "${ENTRY}" ] &amp;&amp; return 0
 done
 return 1
}

MASTER=()
CURRENT=()
FIRST=1
for SERVER in ${SERVERS}; do
 # collect all builds from server and populate CURRENT list
 COMMAND="${LS} -1fd ${WEBROOT}/${SITE}.*"
 BUILDS=`${SSH} ${SSHOPTS} root@${SERVER} "${COMMAND}"`
 for BUILD in ${BUILDS}; do
   CURRENT=( ${CURRENT[@]-} ${BUILD} )
 done

 # if this is our first time around, copy CURRENT to MASTER
 if [ ${FIRST} -eq 1 ]; then
   MASTER=( ${CURRENT[@]} )
   FIRST=0
 fi

 # now we do a compare between MASTER and CURRENT to see what builds
 # are common
 INTERSECT=()
 for ENTRY in ${CURRENT[@]}; do
   in_array "${ENTRY}" "${MASTER[@]}"
   RET=$?
   if [ "${RET}" -eq 0 ]; then
     INTERSECT=( ${INTERSECT[@]-} ${ENTRY} )
   fi
 done
 MASTER=( ${INTERSECT[@]} )

 # clear the CURRENT array
 CURRENT=()
done</pre>
<p>Let me take a moment to explain the code above:</p>
<ul>
<li> In order to check for array intersection, you need an in_array()<br />
function</p>
<ul>
<li>The first argument as the &#8220;needle&#8221; and the second is the<br />
&#8220;haystack&#8221;</li>
<li>We verify that both parameters were passed</li>
<li>We simply loop through the haystack checking for the needle</li>
<li>If we find it, return success.  Otherwise, eventually return<br />
false</li>
</ul>
</li>
<li>We need to loop through each server eventually, but we&#8217;ll start with<br />
the first one</p>
<ul>
<li>Run an SSH command to get a listing of builds</li>
<li>Populate an array ($CURRENT) with the builds that were found</li>
</ul>
<ul>
<li>Since the first server has no previous server to compare with, so we<br />
just copy it to $MASTER</li>
</ul>
</li>
<li>We then loop to the 2nd server, and put the result of getting builds<br />
into $CURRENT</p>
<ul>
<li>Now that we have the first server&#8217;s builds in $MASTER, we perform an<br />
intersect with $CURRENT</li>
<li>We realize the need for an $INTERSECT array to hold the intersections<br />
found above</li>
<li>$INTERSECT becomes $MASTER since it only contains similar builds from<br />
the 1st and 2nd server</li>
</ul>
</li>
<li>Looping to the 3rd server, we get the builds and put them in $CURRENT
<ul>
<li>Since $MASTER contains only the similar builds thus far, we again<br />
compare it with $CURRENT</li>
<li>The intersect can now be used to compare against builds on the 4th<br />
server, and so on</li>
</ul>
</li>
<li>Once you finish looping through all servers, your $MASTER should<br />
contain only similar builds</li>
</ul>
<p>There are a few guides out there which show you how to do this via<br />
forking, but I thought someone may appreciate the elegance of using 100%<br />
bash to accomplish this.  I hope this helps someone else out there!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26269&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/10/26/bash-performing-array-intersection-with-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easy MySQL: how to backup databases to a remote machine</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/vrMwJDwqbr0/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=easy-mysql-how-to-backup-databases-to-a-remote-machine</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/vrMwJDwqbr0/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 21:27:39 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[Backups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=335</guid>
		<description><![CDATA[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. 
Method one &#8211; this writes a remote file.
mysqldump [options] [db_name&#124;--all-databases]&#124; gzip -c &#124; ssh user@host.com "cat &#62; /path/to/new/file.sql.gz"
Method two &#8211; this writes directly into a remote mysql server
mysqldump [options] [db_name&#124;--all-databases]&#124; mysql --host=[remote host] –user=root –password=[pass] [db_name]
]]></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>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/vrMwJDwqbr0" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25560&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25560&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/08/14/easy-mysql-how-to-backup-databases-to-a-remote-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: rotate wordpress posts into headline/feature status</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/kxeJcFESJ20/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-rotate-wordpress-posts-into-headlinefeature-status</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/kxeJcFESJ20/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 00:16:55 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<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[scripts]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=323</guid>
		<description><![CDATA[If you&#8217;re using the new Arthemia theme 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.
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. You can also find the script here: http://pastebin.com/1QqiM5rh &#8211; wordpress is clobbering my line breaks so use the Pastebin version if you want to copy/paste the content. 
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. 
#!/bin/bash
#wordpress connection settings
USER="wordpress"
PASSWORD="password"
HOST="mysql.mysite.com"
DB="wordpress"
MYSQL="/usr/bin/mysql"
#remove current relationship for headline/post, set random post as headline
HEADLINE0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='103'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES ((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'103','0');"
#select current headline post - for reference, we never use this in the script
HEADLINE1="select * from wp_term_relationships where term_taxonomy_id = '103';"
#remove current relationship for featured/post, set random post as featured
FEATURED0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='104'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0');"
#execute queries
echo -n "Updating headline: "
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$HEADLINE0"; do
    echo "[FAILED]"
    echo -n "Running again: "
done
echo "[OK]"
echo -n "Updating featured: "
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$FEATURED0"; do
echo "[FAILED]"
    echo -n "Running again: "
done
echo "[OK]"

]]></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/" >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. You can also find the script here: <a href="http://pastebin.com/1QqiM5rh">http://pastebin.com/1QqiM5rh</a> &#8211; wordpress is clobbering my line breaks so use the Pastebin version if you want to copy/paste the content. </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. </p>
<p><code>#!/bin/bash<br />
#wordpress connection settings<br />
USER="wordpress"<br />
PASSWORD="password"<br />
HOST="mysql.mysite.com"<br />
DB="wordpress"<br />
MYSQL="/usr/bin/mysql"<br />
#remove current relationship for headline/post, set random post as headline<br />
HEADLINE0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='103'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES ((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'103','0');"<br />
#select current headline post - for reference, we never use this in the script<br />
HEADLINE1="select * from wp_term_relationships where term_taxonomy_id = '103';"<br />
#remove current relationship for featured/post, set random post as featured<br />
FEATURED0="DELETE FROM wp_term_relationships WHERE term_taxonomy_id='104'; INSERT INTO wp_term_relationships (object_id,term_taxonomy_id,term_order) VALUES<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0'),<br />
((select ID from wp_posts where post_name NOT LIKE '%autosave%' AND post_name != '' and post_name !='hello-world' AND ID !='2' AND ID !='16' AND ID !='35' AND ID !='44' ORDER BY RAND() LIMIT 1),'104','0');"<br />
#execute queries<br />
echo -n "Updating headline: "<br />
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$HEADLINE0"; do<br />
    echo "[FAILED]"<br />
    echo -n "Running again: "<br />
done<br />
echo "[OK]"<br />
echo -n "Updating featured: "<br />
until $MYSQL --user="$USER" --password="$PASSWORD" --host="$HOST" "$DB" -e "$FEATURED0"; do<br />
echo "[FAILED]"<br />
    echo -n "Running again: "<br />
done<br />
echo "[OK]"<br />
</code></p>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/kxeJcFESJ20" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25504&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25504&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/08/08/how-to-rotate-wordpress-posts-into-headlinefeature-status/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>N900 &#8211; control all of your accounts with this script</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/q9pWVZOsDxg/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=n900-control-all-of-your-accounts-with-this-script</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/q9pWVZOsDxg/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 22:42:27 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[instant messenger]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[N900]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=321</guid>
		<description><![CDATA[If you own a Nokia N900 cellular device you might be interested in the ability to control all of your IM accounts from the command line. For those that do not know, the N900 runs Maemo Linux and is capable of running MySQL embedded if you so choose. Here&#8217;s a quick script I wrote to provide that functionality for IM accounts. It&#8217;s at the bottom of the page, called &#8220;im-connections&#8221;.
wiki: http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline
pastebin: http://pastebin.com/qAC57E1N
]]></description>
			<content:encoded><![CDATA[<p>If you own a Nokia N900 cellular device you might be interested in the ability to control all of your IM accounts from the command line. For those that do not know, the N900 runs Maemo Linux and is capable of running MySQL embedded if you so choose. Here&#8217;s a quick script I wrote to provide that functionality for IM accounts. It&#8217;s at the bottom of the page, called &#8220;im-connections&#8221;.</p>
<p>wiki: <a title="http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline" href="http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline" >http://wiki.maemo.org/N900_Mission_Control#Set_all_SIP_accounts_to_online_or_offline</a><br />
pastebin: <a title="http://pastebin.com/qAC57E1N" href="http://pastebin.com/qAC57E1N" >http://pastebin.com/qAC57E1N</a></p>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/q9pWVZOsDxg" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25409&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=25409&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/07/28/n900-control-all-of-your-accounts-with-this-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get colored output from &#8216;ls&#8217; on Solaris10</title>
		<link>http://feedproxy.google.com/~r/Themattreid/~3/n-rDWCzuWKc/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-get-colored-output-from-ls-on-solaris10</link>
		<comments>http://feedproxy.google.com/~r/Themattreid/~3/n-rDWCzuWKc/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 01:04:17 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[opensolaris]]></category>
		<category><![CDATA[solaris]]></category>
		<category><![CDATA[solars]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://themattreid.com/wordpress/?p=306</guid>
		<description><![CDATA[For all of those linux users out there that have moved over to, or tried out, Solaris10 or OpenSolaris because they heard the tales of how MySQL is faster on Solaris&#8230; or perhaps you wanted to learn how to use Sol10 for the great features of Zones or the ZFS filesystem? Regardless of why you&#8217;re on it you are probably wondering why Linux has colored output of filenames and directories but Solaris does not. The question of &#8216;why?&#8217; isn&#8217;t important, but how to enable colors is. It&#8217;s very simple, and here&#8217;s how I fixed it. This is a result of digging through multiple semi-related links on Google. 

Download all packages from SunFreeware.com

dependency: libintl-3.4.0-sol10-x86-local
dependency: libiconv-1.13.1-sol10-x86-local
dependency: gmp-4.2.1-sol10-x86-local
dependency: gcc-3.4.6-sol10-x86-local or libgcc-3.4.6-sol10-x86-local depending on your system needs
coreutils-8.4-sol10-x86-local

Install &#8216;coreutils&#8217; dependency packages using the command &#8220;pkgadd -d [package_name]
Install &#8216;coreutils&#8217; packages using the command &#8220;pkgadd -d coreutils-8.4-sol10-x86-local
Enable color aliases in your rc file: &#8220;alias ls=&#8217;/usr/local/bin/ls &#8211;color=auto&#8217;&#8221;

]]></description>
			<content:encoded><![CDATA[<p>For all of those linux users out there that have moved over to, or tried out, Solaris10 or OpenSolaris because they heard the tales of how MySQL is faster on Solaris&#8230; or perhaps you wanted to learn how to use Sol10 for the great features of Zones or the ZFS filesystem? Regardless of why you&#8217;re on it you are probably wondering why Linux has colored output of filenames and directories but Solaris does not. The question of &#8216;why?&#8217; isn&#8217;t important, but how to enable colors is. It&#8217;s very simple, and here&#8217;s how I fixed it. This is a result of digging through multiple semi-related links on Google. </p>
<ol>
<li>Download all packages from SunFreeware.com
<ul>
<li>dependency: libintl-3.4.0-sol10-x86-local</li>
<li>dependency: libiconv-1.13.1-sol10-x86-local</li>
<li>dependency: gmp-4.2.1-sol10-x86-local</li>
<li>dependency: gcc-3.4.6-sol10-x86-local or libgcc-3.4.6-sol10-x86-local depending on your system needs</li>
<li>coreutils-8.4-sol10-x86-local</li>
</ul>
<li>Install &#8216;coreutils&#8217; dependency packages using the command &#8220;pkgadd -d [package_name]</li>
<li>Install &#8216;coreutils&#8217; packages using the command &#8220;pkgadd -d coreutils-8.4-sol10-x86-local</li>
<li>Enable color aliases in your rc file: &#8220;alias ls=&#8217;/usr/local/bin/ls &#8211;color=auto&#8217;&#8221;</li>
</ol>
<img src="http://feeds.feedburner.com/~r/Themattreid/~4/n-rDWCzuWKc" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24526&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24526&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/04/27/how-to-get-colored-output-from-ls-on-solaris10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kontrollkit &#8211; new version is available for download!</title>
		<link>http://feedproxy.google.com/~r/Kontrollsoft/~3/71gTxweRiqM/657?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=kontrollkit-new-version-is-available-for-download</link>
		<comments>http://feedproxy.google.com/~r/Kontrollsoft/~3/71gTxweRiqM/657#comments</comments>
		<pubDate>Sat, 27 Feb 2010 01:48:42 +0000</pubDate>
		<dc:creator>Matt Reid</dc:creator>
				<category><![CDATA[announcement]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://kontrollsoft.com/?p=657</guid>
		<description><![CDATA[Just a quick notice to let everyone know that there is a new version of Kontrollkit available. There are two new scripts included as well as some good updates to the my.cnf files. You can download the new version here: http://kontrollsoft.com/software-downloads
kt-mysql-systemcheck &#8211; generates a report for point-in-time system status that is useful for troubleshooting MySQL [...]]]></description>
			<content:encoded><![CDATA[Just a quick notice to let everyone know that there is a new version of Kontrollkit available. There are two new scripts included as well as some good updates to the my.cnf files. You can download the new version here: http://kontrollsoft.com/software-downloads
kt-mysql-systemcheck &#8211; generates a report for point-in-time system status that is useful for troubleshooting MySQL [...]<img src="http://feeds.feedburner.com/~r/Kontrollsoft/~4/71gTxweRiqM" height="1" width="1" /><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23671&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23671&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/02/27/kontrollkit-new-version-is-available-for-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automating MySQL access with expect and bash scripting</title>
		<link>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automating-mysql-access-with-expect-and-bash-scripting</link>
		<comments>http://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 17:08:26 +0000</pubDate>
		<dc:creator>Darren Cassar</dc:creator>
				<category><![CDATA[access]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[expect]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mysqlpreacher.com/wordpress/?p=327</guid>
		<description><![CDATA[If you have multiple database servers with strange names, or if you have to hop over multiple machines to connect to any mysql database server, then you know what a pain it can be to administer such a setup. Thanks to some scripting, you can automate such tasks as follows:
Create an expect script:
/path/to/sshmysql.exp
#!/usr/bin/expect -f
#script by darren cassar
#mysqlpreacher.com
set machine  [lindex $argv 0]
set timeout -1
spawn ssh username@$machine
match_max 100000
expect -exact &#8220;assword: &#8221;
send &#8212; &#8220;password\r&#8221;
send &#8212; &#8220;sudo -k; sudo su &#8211; mysql\r&#8221;
expect -exact &#8220;sudo -k; sudo su &#8211; mysql&#8221;
expect -exact &#8220;assword:&#8221;
send &#8212; &#8220;password\r&#8221;
interact
# you should change the word password in &#8217;send &#8212; &#8220;password\r&#8221;&#8216; to your login password
# if you have the same password for each environment you could also script logging into mysql directly from the same expect script BUT that is not recommended.
Create a bash script:
/path/to/login.sh
#!/bin/bash
#script by darren cassar
#mysqlpreacher.com
sm=&#8217;/path/to/sshmysql.exp&#8217;
menu() {
  echo &#8221; 101 &#8211; dev.databaseserver1 &#8221;
  echo &#8221; 102 &#8211; dev.databaseserver2 &#8221;
  echo &#8221; 103 &#8211; dev.databaseserver3 &#8221;
  echo &#8221; 201 &#8211; qa.databaseserver1 &#8221;
  echo &#8221; 301 &#8211; uat.databaseserver1 &#8221;
  echo &#8221; 302 &#8211; uat.databaseserver2 &#8221;
  echo &#8221; 401 &#8211; prod.databaseserver1 &#8221;
  echo &#8221; &#8221;
}
ARGUMENT=notmenu
if [ -z "$1" ]
  then
    ARGUMENT=menu
else
  choice=$1
fi
if [ $ARGUMENT = "menu" ]
  then
    menu
else
  case &#8220;$choice&#8221; in
  101&#124;dev.databaseserver1   ) $sm dev.databaseserver1;;
  102&#124;dev.databaseserver2   ) $sm dev.databaseserver2;;
  103&#124;dev.databaseserver3   ) $sm dev.databaseserver3;;
  201&#124;qa.databaseserver1   ) $sm qa.databaseserver1;;
  301&#124;uat.databaseserver1   ) $sm uat.databaseserver1;;
  302&#124;uat.databaseserver2   ) $sm uat.databaseserver2;;
  401&#124;prod.databaseserver1   ) $sm prod.databaseserver1;;
  *        ) echo &#8220;Wrong value passed to script&#8221;
             menu ;;
  esac
fi
alias l=&#8217;/path/to/login.sh&#8217;
Output: 
[darrencassar@mymachine ~ ]$ l
 101 &#8211; dev.databaseserver1
 102 &#8211; dev.databaseserver2
 103 &#8211; dev.databaseserver3
 201 &#8211; qa.databaseserver1
 301 &#8211; uat.databaseserver1
 302 &#8211; uat.databaseserver2
 401 &#8211; prod.databaseserver1
Output:
The below command would log you into the first development database server as mysql user.
[darrencassar@mymachine ~ ]$ l 101 
On each machine place aliases for each instance in the .profile
alias use3306=&#8217;mysql -u root -p -h 127.0.0.1 -P 3306 &#8211;prompt=&#8221;mysql \D&#62; &#8220;&#8216;
The above setup can be used using any client/server OS: Linux, Solaris, MAC OS or Windows(running Cygwin)
NOTE: If you store the password in clear text inside the expect script, you should at least save the scripts inside an encrypted partition on your machine and make sure that folder is not shared or accessible by anyone. Another way of doing it would be to use either SSHKeys OR save the password inside a file and encrypt it using OpenSSL
Enjoy!]]></description>
			<content:encoded><![CDATA[<p>If you have multiple database servers with strange names, or if you have to hop over multiple machines to connect to any mysql database server, then you know what a pain it can be to administer such a setup. Thanks to some scripting, you can automate such tasks as follows:</p>
<p>Create an expect script:<br />
/path/to/sshmysql.exp</p>
<blockquote><p>#!/usr/bin/expect -f<br />
#script by darren cassar<br />
#mysqlpreacher.com</p>
<p>set machine  [lindex $argv 0]</p>
<p>set timeout -1</p>
<p>spawn ssh username@$machine<br />
match_max 100000<br />
expect -exact &#8220;assword: &#8221;<br />
send &#8212; &#8220;password\r&#8221;<br />
send &#8212; &#8220;sudo -k; sudo su &#8211; mysql\r&#8221;<br />
expect -exact &#8220;sudo -k; sudo su &#8211; mysql&#8221;<br />
expect -exact &#8220;assword:&#8221;<br />
send &#8212; &#8220;password\r&#8221;<br />
interact</p></blockquote>
<p># you should change the word password in &#8217;send &#8212; &#8220;password\r&#8221;&#8216; to your login password<br />
# if you have the same password for each environment you could also script logging into mysql directly from the same expect script BUT that is not recommended.</p>
<p>Create a bash script:<br />
/path/to/login.sh</p>
<blockquote><p>#!/bin/bash<br />
#script by darren cassar<br />
#mysqlpreacher.com</p>
<p>sm=&#8217;/path/to/sshmysql.exp&#8217;</p>
<p>menu() {<br />
  echo &#8221; 101 &#8211; dev.databaseserver1 &#8221;<br />
  echo &#8221; 102 &#8211; dev.databaseserver2 &#8221;<br />
  echo &#8221; 103 &#8211; dev.databaseserver3 &#8221;<br />
  echo &#8221; 201 &#8211; qa.databaseserver1 &#8221;<br />
  echo &#8221; 301 &#8211; uat.databaseserver1 &#8221;<br />
  echo &#8221; 302 &#8211; uat.databaseserver2 &#8221;<br />
  echo &#8221; 401 &#8211; prod.databaseserver1 &#8221;<br />
  echo &#8221; &#8221;<br />
}</p>
<p>ARGUMENT=notmenu</p>
<p>if [ -z "$1" ]<br />
  then<br />
    ARGUMENT=menu<br />
else<br />
  choice=$1<br />
fi</p>
<p>if [ $ARGUMENT = "menu" ]<br />
  then<br />
    menu<br />
else<br />
  case &#8220;$choice&#8221; in<br />
  101|dev.databaseserver1   ) $sm dev.databaseserver1;;<br />
  102|dev.databaseserver2   ) $sm dev.databaseserver2;;<br />
  103|dev.databaseserver3   ) $sm dev.databaseserver3;;<br />
  201|qa.databaseserver1   ) $sm qa.databaseserver1;;<br />
  301|uat.databaseserver1   ) $sm uat.databaseserver1;;<br />
  302|uat.databaseserver2   ) $sm uat.databaseserver2;;<br />
  401|prod.databaseserver1   ) $sm prod.databaseserver1;;<br />
  *        ) echo &#8220;Wrong value passed to script&#8221;<br />
             menu ;;<br />
  esac<br />
fi</p></blockquote>
<blockquote><p>alias l=&#8217;/path/to/login.sh&#8217;</p></blockquote>
<p>Output: </p>
<blockquote><p>[darrencassar@mymachine ~ ]$ l<br />
 101 &#8211; dev.databaseserver1<br />
 102 &#8211; dev.databaseserver2<br />
 103 &#8211; dev.databaseserver3<br />
 201 &#8211; qa.databaseserver1<br />
 301 &#8211; uat.databaseserver1<br />
 302 &#8211; uat.databaseserver2<br />
 401 &#8211; prod.databaseserver1</p></blockquote>
<p>Output:<br />
The below command would log you into the first development database server as mysql user.</p>
<blockquote><p>[darrencassar@mymachine ~ ]$ l 101 </p></blockquote>
<p>On each machine place aliases for each instance in the .profile</p>
<blockquote><p>alias use3306=&#8217;mysql -u root -p -h 127.0.0.1 -P 3306 &#8211;prompt=&#8221;mysql \D> &#8220;&#8216;</p></blockquote>
<p>The above setup can be used using any client/server OS: Linux, Solaris, MAC OS or Windows(running Cygwin)</p>
<p><strong>NOTE: If you store the password in clear text inside the expect script, you should at least save the scripts inside an encrypted partition on your machine and make sure that folder is not shared or accessible by anyone. Another way of doing it would be to use either SSHKeys OR save the password inside a file and encrypt it using <a href="http://www.madboa.com/geek/openssl/#encrypt-simple" >OpenSSL</a></strong></p>
<p>Enjoy!</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23385&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23385&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/02/08/automating-mysql-access-with-expect-and-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

