<?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>Fri, 10 Sep 2010 11:16:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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&amp;utm_medium=rss&amp;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[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[mysqldump]]></category>
		<category><![CDATA[scp]]></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://feedproxy.google.com/~r/Themattreid/~3/vrMwJDwqbr0/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&amp;utm_medium=rss&amp;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[Scripting]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scripts]]></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://feedproxy.google.com/~r/Themattreid/~3/kxeJcFESJ20/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&amp;utm_medium=rss&amp;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[Linux]]></category>
		<category><![CDATA[N900]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[instant messenger]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[programming]]></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://feedproxy.google.com/~r/Themattreid/~3/q9pWVZOsDxg/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&amp;utm_medium=rss&amp;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[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></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://feedproxy.google.com/~r/Themattreid/~3/n-rDWCzuWKc/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&amp;utm_medium=rss&amp;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[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[announcement]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql server]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></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://feedproxy.google.com/~r/Kontrollsoft/~3/71gTxweRiqM/657/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&amp;utm_medium=rss&amp;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[Databases]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[expect]]></category>
		<category><![CDATA[mysql]]></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://mysqlpreacher.com/wordpress/2010/02/automating-mysql-access-with-expect-and-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
