<?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>HandsomePlanet &#187; regex</title>
	<atom:link href="http://www.handsomeplanet.com/archives/tag/regex/feed" rel="self" type="application/rss+xml" />
	<link>http://www.handsomeplanet.com</link>
	<description>technology and other perplexities</description>
	<lastBuildDate>Sun, 05 Sep 2010 02:26:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Fixing broken mysql / mysql-server under Ubuntu 9.04 (Jaunty) after a purge</title>
		<link>http://www.handsomeplanet.com/archives/38</link>
		<comments>http://www.handsomeplanet.com/archives/38#comments</comments>
		<pubDate>Sat, 13 Jun 2009 00:25:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.handsomeplanet.com/?p=38</guid>
		<description><![CDATA[I broke my server attempting to do some clean-up before making bigger changes.   mysql would not restart, and the culprit was something like  &#8216;apt-get purge mysql-server,&#8217; which deleted the /etc/mysql directory .  Various installs brought back /etc/mysql but without solving the problem: % sudo apt-get install mysql-server mysql-common Setting up mysql-server-5.0 (&#8230;) * Stopping MySQL [...]]]></description>
			<content:encoded><![CDATA[<p>I broke my server attempting to do some clean-up before making bigger changes.   mysql would not restart, and the culprit was something like  &#8216;apt-get purge mysql-server,&#8217; which deleted the /etc/mysql directory .  Various installs brought back /etc/mysql but without solving the problem:</p>
<p>% sudo apt-get install mysql-server mysql-common</p>
<blockquote><p>Setting up mysql-server-5.0 (&#8230;)<br />
* Stopping MySQL database server mysqld                                 [ OK ]<br />
* Starting MySQL database server mysqld                                  [fail]<br />
invoke-rc.d: initscript mysql, action &#8220;start&#8221; failed.<br />
dpkg: error processing mysql-server-5.0 (&#8211;configure):<br />
subprocess post-installation script returned error exit status 1<br />
dpkg: dependency problems prevent configuration of mysql-server:<br />
mysql-server depends on mysql-server-5.0; however:<br />
Package mysql-server-5.0 is not configured yet.<br />
dpkg: error processing mysql-server (&#8211;configure):<br />
dependency problems &#8211; leaving unconfigured<br />
No apport report written because the error message indicates its a followup error from a previous failure.<br />
Errors were encountered while processing:<br />
mysql-server-5.0<br />
mysql-server<br />
E: Sub-process /usr/bin/dpkg returned an error code (1)</p></blockquote>
<blockquote><p>/var/log/dpkg:<br />
2009-06-12 17:23:31 status half-installed mysql-server 5.1.30really5.0.75-0ubuntu10.2</p></blockquote>
<p>In any case, the only way I could get things back running was to copy over the /etc/mysql directory from a working server,  doing</p>
<p>% sudo apt-get remove &#8211;purge mysql-server<br />
% sudo apt-get install mysql-server</p>
<p>and rebooting.</p>
<p>Here&#8217;s what the /etc/mysql directory looked like after the copy:</p>
<p><code>/etc/mysql# ls -l<br />
total 16<br />
drwxr-xr-x 2 root root 4096 2009-06-12 17:23 conf.d<br />
-rw------- 1 root root  312 2009-06-12 17:23 debian.cnf<br />
-rwxr-xr-x 1 root root 1198 2009-05-14 05:39 debian-start<br />
-rw-r--r-- 1 root root 4088 2009-03-30 15:18 my.cnf<br />
/etc/mysql# ls -l conf.d/<br />
total 0</code></p>
<p>So, the copy provided the conf.d directory and the my.cnf file that the re-install failed to (re)create.</p>
<p>I&#8217;ve uploaded a copy of the default Ubuntu 9.04 /etc/mysql/my.cnf file <a title="my.cnf" href="http://www.handsomeplanet.com/wp-content/uploads/2009/06/my.cnf">here</a>.</p>
<p>And here&#8217;s just the active info from my.cnf file<br />
(filtered through <code>egrep -v '^$|^#' my.cnf </code> to remove empty lines and comment lines) :</p>
<p>&#8212;&#8211;start my.cnf&#8212;&#8212;</p>
<p><code> [client]<br />
port        = 3306<br />
socket        = /var/run/mysqld/mysqld.sock<br />
[mysqld_safe]<br />
socket        = /var/run/mysqld/mysqld.sock<br />
nice        = 0<br />
[mysqld]<br />
user        = mysql<br />
pid-file    = /var/run/mysqld/mysqld.pid<br />
socket        = /var/run/mysqld/mysqld.sock<br />
port        = 3306<br />
basedir        = /usr<br />
datadir        = /var/lib/mysql<br />
tmpdir        = /tmp<br />
skip-external-locking<br />
bind-address        = 127.0.0.1<br />
key_buffer        = 16M<br />
max_allowed_packet    = 16M<br />
thread_stack        = 128K<br />
thread_cache_size    = 8<br />
myisam-recover        = BACKUP<br />
query_cache_limit       = 1M<br />
query_cache_size        = 16M<br />
expire_logs_days    = 10<br />
max_binlog_size         = 100M<br />
skip-federated<br />
[mysqldump]<br />
quick<br />
quote-names<br />
max_allowed_packet    = 16M<br />
[mysql]<br />
[isamchk]<br />
key_buffer        = 16M<br />
!includedir /etc/mysql/conf.d/</code></p>
<p>&#8212;&#8211;end my.cnf&#8212;&#8212;</p>
<p>Recreating that file may help you get mysql back running, as it appears to have been essential for me.</p>
<p>Incidentally, here is a handy search for printing which logfiles have info about your misbehaving program (in this case, mysql):</p>
<p><code>/var/log# egrep mysql * | awk -F: '{print $1}' | uniq</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.handsomeplanet.com/archives/38/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple output filter for “show cdp neighbors” using a compound regular expression (Cisco IOS)</title>
		<link>http://www.handsomeplanet.com/archives/16</link>
		<comments>http://www.handsomeplanet.com/archives/16#comments</comments>
		<pubDate>Sat, 23 May 2009 20:30:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[Cisco]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://www.handsomeplanet.com/?p=16</guid>
		<description><![CDATA[Here is a simple filter I&#8217;ve used on ’show cdp’ output, which lets me get information quickly. MalbecMDF#show cdp neighbor detail &#124; include (---&#124;Device ID&#124;IP address&#124;Platform) In practice, I generally cut the command down to: sh cdp ne d &#124; inc (blah&#124;blah) It is probably best to start with obvious match choices, before pairing them [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple filter I&#8217;ve used on ’show cdp’ output, which lets me get information quickly.</p>
<p><code>MalbecMDF#show cdp neighbor detail | include (---|Device ID|IP address|Platform)</code></p>
<p>In practice, I generally cut the command down to:<br />
<code>sh cdp ne d | inc (blah|blah)</code><br />
It is probably best to start with obvious match choices, before pairing them down, as you can find yourself surprised with the text that is grabbed from different types of devices if you’re basing your regular expression match on a small sample.</p>
<p>In any case, the output should come out something like this:<br />
<code><br />
MalbecMDF#sh cdp ne d | inc (---|e ID|IP add|Plat)<br />
-------------------------<br />
Device ID: SummaC-6509<br />
IP address: 10.77.234.131<br />
Platform: cisco WS-C6509-E,  Capabilities: Router Switch IGMP<br />
-------------------------<br />
Device ID: Malbec-AP10<br />
IP address: 10.88.129.22<br />
Platform: cisco AIR-AP1231G-A-K9    ,  Capabilities: Trans-Bridge<br />
-------------------------<br />
Device ID: Malbec-AP11<br />
IP address: 10.88.129.29<br />
Platform: cisco AIR-AP1231G-A-K9    ,  Capabilities: Trans-Bridge<br />
-------------------------</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.handsomeplanet.com/archives/16/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cisco IOS CLI regular expressions, Part II — ‘AND’</title>
		<link>http://www.handsomeplanet.com/archives/11</link>
		<comments>http://www.handsomeplanet.com/archives/11#comments</comments>
		<pubDate>Thu, 02 Apr 2009 21:25:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[Cisco]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://www.handsomeplanet.com/?p=11</guid>
		<description><![CDATA[In an earlier post, I talked about Cisco command line regular expressions, and held off on giving any good examples of using the CLI regexp tools to get ‘AND’ functionality. ( I pointed out there that the ‘&#124;’ (pipe symbol) could be used as a simple ‘OR’ function.) Here are some easy regexp’s that function [...]]]></description>
			<content:encoded><![CDATA[<p>In an earlier <a title="cisco-ios-cli-regular-expressions">post</a>, I talked about Cisco command line regular expressions, and held off on giving any good examples of using the CLI regexp tools to get ‘AND’ functionality. ( I pointed out there that the ‘|’ (pipe symbol) could be used as a simple ‘OR’ function.)<br />
Here are some easy regexp’s that function (more as less) as simple Boolean ‘AND’s.</p>
<p>Here’s a scenario: you’re auditing one of your routers, checking to make sure privilege levels are what they should be for individual users, and that commands that have been moved into non-default privilege levels that appear to be correctly defined.</p>
<p>Here’s the output of ’show running-config’ with only lines that match ‘privi’ included (so as to catch lines that show privilege levels):</p>
<p><code>IOS-rtr#sh run | inc privi</code><br />
<code>username sneezy privilege 0 secret 5 $1$Dz6cKoEINsYusITt.l</code><br />
<code>username dopey privilege 0 secret 5 $1$MIUYWJ.I3iGq/qNleB.</code><br />
<code>username meson privilege 0 secret 5 $1$7uBWyjan.5JB8KHR0</code><br />
<code>username gluon privilege 15 secret 5 $1$VuoC$09dsgXRB.A/d</code><br />
<code>privilege exec level 0 traceroute</code><br />
<code>privilege exec level 0 ping</code><br />
<code>privilege exec all level 0 show</code><br />
<code>privilege exec level 0 clear ip nat translation</code><br />
<code>privilege exec level 0 clear ip nat</code><br />
<code>privilege exec level 0 clear ip</code><br />
<code>privilege exec level 0 clear</code><br />
<code>privilege configure level 7 logging </code><br />
<code>privilege configure level 7 logging trap </code><br />
<code>privilege configure level 7 logging source</code><br />
<code> privilege level 15</code><br />
<code> privilege level 15</code></p>
<p>In this case, you can use the regular expression “.*” (dot-star) to match lines that contain both the word ‘privilege’ and ‘level 0′, thus eliminating other priv levels, as well as username definitions:<br />
<code>IOS-rtr#sh run | inc privi.*level 0</code><br />
<code>privilege exec level 0 traceroute</code><br />
<code>privilege exec level 0 ping</code><br />
<code>privilege exec all level 0 show</code><br />
<code>privilege exec level 0 clear ip nat translation</code><br />
<code>privilege exec level 0 clear ip nat</code><br />
<code>privilege exec level 0 clear ip</code><br />
<code>privilege exec level 0 clear</code></p>
<p>The same thing works for an audit of ‘level 7′ commands:</p>
<p><code>OS-rtr#sh run | inc privi.*level 7</code><br />
<code>privilege configure level 7 logging </code><br />
<code>privilege configure level 7 logging trap </code><br />
<code>privilege configure level 7 logging source</code></p>
<p>If you want to show lines that match privilege levels <em>other</em> than zero, you could use this:<br />
<code>IOS-rtr#sh run | inc priv.*[1-9]</code></p>
<p>You should note that the “.*” (dot-star) regular expression can be used as a synonym for AND, provided that you are aware that “.*” is not order agnostic.<br />
In order to do a true AND, you’d need an expression like :<br />
<code>sh run | inc (privi.*level 0|level 0.*privi)</code><br />
This will match lines containing both ‘privilege’ and ‘level 0′, no matter which of the words appears first. To illustrate this, I’ll create a loopback interface (loop3) with some description text that will match the regex:</p>
<p><code>IOS-rtr#conf t</code><br />
<code>Enter configuration commands, one per line.  End with CNTL/Z.</code><br />
<code>IOS-rtr(config)#int loop3</code><br />
<code>IOS-rtr(config-if)#desc level 0 is not privileged here!</code><br />
<code>IOS-rtr(config-if)#^Z</code><br />
<code>IOS-rtr#sh run | inc (privi.*level 0|level 0.*privi)</code><br />
<code> description level 0 is not privileged here!</code><br />
<code>privilege exec level 0 traceroute</code><br />
<code>privilege exec level 0 ping</code><br />
<code>privilege exec all level 0 show</code><br />
<code>privilege exec level 0 clear ip nat translation</code><br />
<code>privilege exec level 0 clear ip nat</code><br />
<code>privilege exec level 0 clear ip</code><br />
<code>privilege exec level 0 clear</code></p>
<p>It works!   Notice that we caught both the description line and the privilege exec lines.</p>
<p>Apparently I’m easily amused, but there it is.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.handsomeplanet.com/archives/11/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cisco IOS CLI regular expressions (&#8220;Ceci n&#8217;est pas une pipe.&#8221;)</title>
		<link>http://www.handsomeplanet.com/archives/7</link>
		<comments>http://www.handsomeplanet.com/archives/7#comments</comments>
		<pubDate>Tue, 31 Mar 2009 15:09:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[Cisco]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://www.handsomeplanet.com/?p=7</guid>
		<description><![CDATA[[taken from a  note originally written March 2007] Yesterday, I was trying to find a method to implement an  ‘AND’ function within the Cisco IOS cisco command line.  I was familiar with the  ‘OR’ function available through the ‘&#124;’ symbol (which is to say, the same symbol as the pipe). For example, if you wanted [...]]]></description>
			<content:encoded><![CDATA[<address>[taken from a  note originally written March 2007]<br />
</address>
<p>Yesterday, I was trying to find a method to implement an  ‘AND’ function within the Cisco IOS cisco command line.  I was familiar with the  ‘OR’ function available through the ‘|’ symbol (which is to say, the same symbol as the pipe).</p>
<p>For example, if you wanted to show the running config, and filter out lines that contained either ‘foo’ or ‘bar’, you could type</p>
<p><code>show run | include foo|bar</code></p>
<p>The second &#8220;pipe,&#8221;  in this case, isn’t a pipe, but the symbol for an ‘OR’ function.  (&#8220;Ceci n&#8217;est pas une pipe.&#8221;)</p>
<p><a href="http://en.wikipedia.org/wiki/The_Treachery_of_Images"><img class="size-full wp-image-35 alignright" title="300px-magrittepipe" src="http://www.handsomeplanet.com/wp-content/uploads/2009/03/300px-magrittepipe.jpg" alt="Magritte -- this (pipe) is not a pipe" width="300" height="230" /></a></p>
<p>I wasn’t able to find a way to do an ‘AND’ in an analogous fashion, but I  did find a decent Cisco webpage on CLI and regular expressions (regexp) that helped a bit. That page can be found here: <a title="http://www.cisco.com/univercd/cc/td/doc/product/software/ios120/120newft/120t/120t1/cliparse.htm" onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.cisco.com/univercd/cc/td/doc/product/software/ios120/120newft/120t/120t1/cliparse.htm" target="_blank">http://www.cisco.com/univercd/cc/td/doc/product/software/ios120/120newft/120t/120t1/cliparse.htm </a></p>
<p>It is possible to do ‘AND’ type functions implicitly by using a more complex set of matching rules based on regular expressions.</p>
<p>Here’s a example that shows (from an interactive session on the Cisco CLI) if access-lists have been applied to interfaces using the &#8220;access-group&#8221; command:</p>
<p><code>sh run | include (^interface [A-Z])|(ip access-group [0-9a-zA-Z])</code></p>
<p>Lines that start with ‘interface’ followed by an uppercase letter (the expression matches anything in the range A-Z) are supposed to match things like ‘interface Fastethernet,’ ‘interface Serial’ and so on. The second part of the expression matches access-groups that have three possible initial character ranges: a lowercase letter (a-z), an uppercase letter (A-Z), or a number (0-9) for the standard access lists.<br />
Some rudimentary filtering is done, so things like Loopback sourcing, route-maps, and so on, don’t match.</p>
<p>Interfaces that have no access-lists applied have on the interface name listed, but interfaces with an access-group command show the complete access-group statement under the relevant interface (which makes sense, given that this is only a filtered ’show run’).</p>
<p>Output might look something like this:</p>
<p><code>interface Serial3/3<br />
interface Serial3/3.1 point-to-point<br />
ip access-group pac in<br />
ip access-group ket out<br />
interface FastEthernet4/0<br />
interface Serial6/0<br />
ip access-group Ozona in</code></p>
<p>If this kind of function is useful for you, it is even easier to use if you put it in an alias on your switch or router:</p>
<p><code>#conf t<br />
#alias exec shag sh run | include (^interface [A-Z])|(ip access-group [0-9a-zA-Z])</code></p>
<p>You should, of course, pick a name for the alias that you’ll remember.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.handsomeplanet.com/archives/7/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
