<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6554094098448561896</id><updated>2011-11-27T20:07:49.901-05:00</updated><category term='regex'/><category term='hp proliant debian sarge sata usb raid linux'/><category term='redirection'/><category term='logs'/><category term='shell'/><category term='uptime disaster recovery network availability raid prevention reliability redundancy monitoring logwatch nagios augur Netcool disaster contingency change backup  Maintenance'/><category term='web'/><category term='unix'/><category term='grep'/><category term='tutorial'/><category term='linux mac os X'/><category term='regular expressions'/><category term='pipe'/><title type='text'>logTail</title><subtitle type='html'>Helping individuals and businesses of all sizes achieve stable and productive Linux network environments</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://logtail.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://logtail.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Shaun</name><uri>http://www.blogger.com/profile/08447246104796576101</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6554094098448561896.post-3901441264138733819</id><published>2007-04-26T21:11:00.000-04:00</published><updated>2007-04-26T22:01:31.015-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='redirection'/><category scheme='http://www.blogger.com/atom/ns#' term='logs'/><category scheme='http://www.blogger.com/atom/ns#' term='pipe'/><category scheme='http://www.blogger.com/atom/ns#' term='grep'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='regex'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='regular expressions'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>Basic Regular Expressions with grep</title><content type='html'>&lt;a href="http://www.digg.com/"&gt;&lt;br /&gt;&lt;img src="http://digg.com/img/badges/100x20-digg-button.gif" alt="Digg!" height="20" width="100" /&gt;&lt;br /&gt;&lt;/a&gt;&lt;br /&gt;In a previous post, &lt;a href="http://logtail.blogspot.com/2007/04/how-to-search-logs-using-grep-part-1.html"&gt;How to Search Logs Using grep Part 1&lt;/a&gt;, I talked about some basic concepts such as:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;basic pipe concepts&lt;/li&gt;&lt;ul&gt;&lt;li&gt;cat file.txt | sort&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;basic grep usage&lt;/li&gt;&lt;ul&gt;&lt;li&gt;cat file.txt | grep &lt;span style="font-style: italic;"&gt;pattern&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;chaining input from one instance of grep to another&lt;/li&gt;&lt;ul&gt;&lt;li&gt;cat file.txt | grep &lt;span style="font-style: italic;"&gt;pattern1&lt;/span&gt; | grep &lt;span style="font-style: italic;"&gt;pattern2&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;inverse grepping&lt;/li&gt;&lt;ul&gt;&lt;li&gt;cat file.txt | grep -v &lt;span style="font-style: italic;"&gt;pattern&lt;/span&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;Have a look at this post if you want more on the theory and practice behind the basic use of grep.  For this installment, we will look at regular expression patterns and some other techniques that will allow you to quickly setup extremely accurate patterns on the fly for just about anything you'd like to match.  So, let's get right down to it!&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Regular Expressions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Regular expressions, or "regex" for short, is a huge topic that has a pile of books all its own.  For our purposes, though, we can do a lot with just the basics.  The idea is to use a special syntax to represent characters or groups of characters in a line. It can be considered line-oriented, just like grep, so they're perfect for each other.   Here are some basic regex patterns.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;^        Matches the beginning of the line before the first&lt;br /&gt;         character&lt;br /&gt;$        Matches the end of the line after the last&lt;br /&gt;         character&lt;br /&gt;.        Matches a single character.  Any character at all&lt;br /&gt;.*       Matches any number of characters&lt;br /&gt;a        Matches the letter a, for example&lt;br /&gt;[xyz]    Matches one x, one y or one z&lt;br /&gt;[xyz]*   Matches any number of x,y,and z characters. "xyzzy"&lt;br /&gt;         would be matched, for instance.&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;If you've never used regex before, the info above is going to be pretty confusing.  Don't worry about it now, we'll just jump right into some examples using grep.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Basic Regex with grep&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For these examples, we will use a file named data.txt containing the following lines:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;alpha is 1st.  Nothing comes before alpha&lt;br /&gt;beta is 2nd.  Beta comes after alpha&lt;br /&gt;gamma is 3rd.  Gamma comes after beta&lt;br /&gt;delta is 4th.  Delta comes after gamma&lt;br /&gt;epsilon is 5th. comes after delta&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When I first introduced grep, I suggested that you do something like this:&lt;br /&gt;&lt;br /&gt;cat data.txt | grep &lt;span style="font-style: italic;"&gt;pattern&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;grep can, in fact, read a file on its own without the need to pipe  data into it.  This is a shortcut since grep is so commonly used on files.  here's the syntax we will be using:&lt;br /&gt;&lt;br /&gt;grep &lt;span style="font-style: italic;"&gt;'pattern&lt;/span&gt;' &lt;span style="font-style: italic;"&gt;filename&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Pretty simple.  We will be using single quotes around patterns from now on.  Unix/Linux shells can try to misinterpret parts our patterns if we are using all kinds of special characters in them, so this is the easiest way to tell the shell to ignore them and pass them as a chunk to grep for it to deal with.&lt;br /&gt;&lt;br /&gt;Let's get started on some basic regex patterns.  Suppose we would like to search our file for any lines beginning with the word "alpha".  Lets try it without regex.&lt;br /&gt;&lt;br /&gt;grep 'alpha' data.txt&lt;br /&gt;alpha is 1st.  Nothing comes before alpha&lt;br /&gt;beta is 2nd.  Beta comes after alpha&lt;br /&gt;&lt;br /&gt;Problem! we got back two lines since the word "alpha" is in both of them.  Let's use a basic regular expression to be more specific.&lt;br /&gt;&lt;br /&gt;grep -e '^alpha' data.txt&lt;br /&gt;alpha is 1st.  Nothing comes before alpha&lt;br /&gt;&lt;br /&gt;That works.  We used the ^ to signify that we want to match the beginning of the line, followed by "alpha".  So this can be read as "Match the beginning of the line, then the letters alpha".  It's also interesting to note here that we are telling it match 5 characters, a l p h a, not necessarily the word "alpha".  More on that in a bit.&lt;br /&gt;&lt;br /&gt;Lets use the same pattern again, but modify it to illustrate the '.' as a replacement for a single character.&lt;br /&gt;&lt;br /&gt;grep -e '^.lpha' data.txt&lt;br /&gt;alpha is 1st.  Nothing comes before alpha&lt;br /&gt;&lt;br /&gt;This can be read as "Match the beginning of the line, any single character at all, then the letters lpha".  So, it would match alpha, Alpha, blpha, 6lpha, etc.  any single character, any at all in that position would be a valid match.&lt;br /&gt;&lt;br /&gt;Let's work with the "." a bit more, since it's simple but flexible.  If we combine the "." with the "*", then we can build the expression for "Match any number of any characters".  Example:&lt;br /&gt;&lt;br /&gt;grep -e '^gamma.*beta$' data.txt&lt;br /&gt;gamma is 3rd.  Gamma comes after beta&lt;br /&gt;&lt;br /&gt;This can be read as "Match the beginning of the line, the letters gamma, any number of characters, then the letters beta, then the end of the line".  Since we're now working with a complete regular expression describing a full line, it's good form to tell grep where the end of the line is by using '$'.  It's not strictly necessary here, but it's a good habit to think in these terms.&lt;br /&gt;&lt;br /&gt;So, we've actually done something new here... we've matched two terms we were looking for using one single expression.  We've also told it the order in which the terms appear and where they are in the line of text.  Another example to really illustrate what we've done so far:&lt;br /&gt;&lt;br /&gt;grep -e '^gamma.*Ga..a .om.s a..er be.*$' data.txt&lt;br /&gt;gamma is 3rd.  Gamma comes after beta&lt;br /&gt;&lt;br /&gt;So, that looks pretty complicated, and I won't begin to try to explain each item matched. What is important to note is that the "." matches any single character, and the ".*" matches a series of any characters.&lt;br /&gt;&lt;br /&gt;Let's try something new.  The "[]", or bracket, syntax allows us to specific a group of characters that we may possibly want to match.  It does a bit more, but we'll get into that later.  For now, lets see an example of the bracket syntax.&lt;br /&gt;&lt;br /&gt;grep -e '^.*[123].*$' data.txt&lt;br /&gt;alpha is 1st.  Nothing comes before alpha&lt;br /&gt;beta is 2nd.  Beta comes after alpha&lt;br /&gt;gamma is 3rd.  Gamma comes after beta&lt;br /&gt;&lt;br /&gt;This expression can be read as "Match the beginning of the line, any number of characters, any single character from the set of 1,2,3, any number of characters, then the end of the line".  This is an extremely useful syntax as it allows you to create patterns like this:&lt;br /&gt;&lt;br /&gt;[aA]pril [456789]th&lt;br /&gt;&lt;br /&gt;This would match "April 5th", "april 9th", "april 6th", "April 8th" and so on.&lt;br /&gt;&lt;br /&gt;Sometimes it can get tedious, however, if you're trying to do things that fall into ranges.  0-9, a-z, etc.  Conveniently enough, the bracket syntax understands ranges! here's an example.&lt;br /&gt;&lt;br /&gt;grep -e '^.*[2-5].*$' data.txt&lt;br /&gt;beta is 2nd.  Beta comes after alpha&lt;br /&gt;gamma is 3rd.  Gamma comes after beta&lt;br /&gt;delta is 4th.  Delta comes after gamma&lt;br /&gt;epsilon is 5th. comes after delta&lt;br /&gt;&lt;br /&gt;So, the [2-5] here simply says "Match any single character that ranges between 2 and 5".  Extremely useful.   The bracket syntax can also support the following:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[a-z]        any lowercase letter a through z&lt;br /&gt;[A-Z]        same, but an uppercase letter&lt;br /&gt;[0-9]        any number zero through 9&lt;br /&gt;[a-zA-Z]     any letter, capital or otherwise&lt;br /&gt;[a-zA-Z0-9]  any number or letter&lt;br /&gt;[0-9.]       any number OR a period.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Since the goal here is to leave you with a basic knowledge of the most useful aspects of regex, we'll stop here.  Basic use of regex is one of the key skills that will allow you to easily swim through log files and other line-oriented data very quickly.   If you find yourself needing to scan logs on a regular basis, internalizing some basic regex will make your life a lot easier.&lt;br /&gt;&lt;br /&gt;In an upcoming post, I will discuss how to use this as it relates to searching and processing logs.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.ggiw.com/tracklt01.gif" /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6554094098448561896-3901441264138733819?l=logtail.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://logtail.blogspot.com/feeds/3901441264138733819/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6554094098448561896&amp;postID=3901441264138733819' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/3901441264138733819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/3901441264138733819'/><link rel='alternate' type='text/html' href='http://logtail.blogspot.com/2007/04/basic-regular-expressions-with-grep.html' title='Basic Regular Expressions with grep'/><author><name>Shaun</name><uri>http://www.blogger.com/profile/08447246104796576101</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6554094098448561896.post-5317298263330819624</id><published>2007-04-01T23:54:00.000-04:00</published><updated>2007-04-05T20:08:40.195-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='redirection'/><category scheme='http://www.blogger.com/atom/ns#' term='logs'/><category scheme='http://www.blogger.com/atom/ns#' term='linux mac os X'/><category scheme='http://www.blogger.com/atom/ns#' term='pipe'/><category scheme='http://www.blogger.com/atom/ns#' term='grep'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>How to Search Logs Using grep, Part 1</title><content type='html'>&lt;img src="http://www.ggiw.com/tracklt01.gif"&gt;&lt;br /&gt;&lt;br /&gt;Here is something that I could write a book about.. or a few good chapters on.   grep is one of the key tools in the traditional Unix arsenal for tearing through text files and finding exactly what you want very, very quickly.  It doesn't take long to master if you have the right tools.&lt;br /&gt;&lt;br /&gt;First, you're going to need to understand how to use pipes.  If you aren't familiar with pipes or use them regularly, it would definitely be worth your while to dig into this.  If folks would be interested in a complete pipe tutorial here, or may know of a good one online, please comment.  That said, I will give a short overview.&lt;br /&gt;&lt;br /&gt;suppose we have a text file called "data.txt" with the following contents:&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;delta is 4th&lt;br /&gt;alpha is 1st&lt;br /&gt;gamma is 3rd&lt;br /&gt;beta is 2nd&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;the following command would display the contents of that file in your terminal&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cat data.txt&lt;/span&gt;&lt;br /&gt;delta is 4th&lt;br /&gt;alpha is 1st&lt;br /&gt;gamma is 3rd&lt;br /&gt;beta is 2nd&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;What "cat data.txt" did was really read the file, &lt;span style="font-style: italic;"&gt;line by line&lt;/span&gt;, and output it to your terminal, line by line.  Yes, line by line, is the key term here.  The term for "output to terminal" is &lt;span style="font-weight: bold;"&gt;standard out&lt;/span&gt;.  We will use that going forward.&lt;br /&gt;&lt;br /&gt;suppose I wanted to do something useful to this data.  I can combine the "cat" command with the "sort" command.  What "sort" does is read, line by line, everything you give it until it detects the end of the file.  Suppose we type the following command:&lt;br /&gt;&lt;br /&gt;&lt;tt style="font-weight: bold;"&gt;sort&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;It just sits there, doing nothing.  It's waiting for some data to come in on the terminal (or,  better termed, &lt;span style="font-weight: bold;"&gt;standard input&lt;/span&gt;).   That's pretty useless most of the time!  But remember that "cat" will read a file and send it, line by line, to the terminal?  Well, using a pipe, we can take those lines from cat and feed them into sort.&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cat data.txt | sort&lt;/span&gt;&lt;br /&gt;alpha is 1st&lt;br /&gt;beta is 2nd&lt;br /&gt;gamma is 3rd&lt;br /&gt;delta is 4th&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;Now we have something useful!  What we have done above can be described by this statement "Take the output of cat data.txt and pipe it through sort".  Many, many commands work in Unix (or Linux/MacOS/etc) will act like "sort" did and accept input line by line.  by stringing together commands that print output to the terminal and commands that read from the terminal, you can do some very powerful things.  grep is one of those commands.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;grepping&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now that we have the basics of pipes squared away, we can get into some more interesting and useful stuff.   grep can be described as a program that reads from standard input, tests each line against a pattern, and  writes to standard output the lines that match this pattern.  It can do a lot more, but this is a good working definition to start.  Here's an example:&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cat data.txt | grep gamma&lt;/span&gt;&lt;br /&gt;gamma is 4th&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;What we've done here told "cat" to read every line of the file "data.txt" and pipe it into grep.  grep took each line that came in and checked to see if the pattern "gamma" appeared on that line.  when it did, it displayed the line.  What happens if no lines match the pattern?&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cat data.txt | grep epsilon&lt;/span&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;grep only outputs the lines that match.  If no lines match, then nothing is sent to standard output.&lt;br /&gt;&lt;br /&gt;Note that grep reads in lines from standard input and outputs lines to standard output.  That means it can be both a consumer and a provider of lines for other commands that can process standard input.  That is huge... More on that later.&lt;br /&gt;&lt;br /&gt;Let's try a more complex example with the same file.&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cat data.txt | grep l&lt;/span&gt;&lt;br /&gt;delta is 4th&lt;br /&gt;alpha is 1st&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;Great, we matched every line with an "l" (the letter l) in it and displayed it to standard input.  Looks like it's out of order, though, so lets sort it after it comes out of grep.&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cat data.txt | grep l | sort&lt;/span&gt;&lt;br /&gt;alpha is 1st&lt;br /&gt;delta is 4th&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;So we had "cat" read data.txt line by line, piped it through grep looking for "l" and piped the results through sort.  You can chain commands like this indefinitely as long as they're reading from standard in and outputting to standard out.&lt;br /&gt;&lt;br /&gt;Lets try something else:&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cat data.txt | grep l | grep p&lt;/span&gt;&lt;br /&gt;alpha is 1st&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;grep can read another grep's output!&lt;br /&gt;&lt;br /&gt;Let's work on some logs now.  Suppose I have an apache log where I'd like to see all of the lines that match a hit to a certain URL.  Lets try this:&lt;br /&gt;&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:85%;" &gt;cat /var/log/httpd/access.log | grep "GET /signup.jsp"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;4.2.2.1 - - [01/Apr/2007:18:19:45 -0700] "GET /signup.jsp HTTP/1.1" 200 4664 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"&lt;br /&gt;10.1.1.1 - - [01/Apr/2007:18:22:48 -0700] "GET /signup.jsp HTTP/1.1" 200 4664 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11"&lt;br /&gt;192.168.0.1 - - [01/Apr/2007:18:23:08 -0700] "GET /signup.jsp HTTP/1.1" 200 4664 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11"&lt;br /&gt;&lt;/span&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;Great.  now we have searched the entire log and filtered out only those hits to that particular IP.  What if I wanted to know who came in on a Mac?&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:85%;" &gt;cat /var/log/httpd/access.log | grep "GET /signup.jsp" | grep "Mac OS X"&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;4.2.2.1 - - [01/Apr/2007:18:19:45 -0700] "GET /signup.jsp HTTP/1.1" 200 4664 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"&lt;/span&gt;&lt;/tt&gt;&lt;span style="font-size:78%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;That covers basic grepping.  To review, you can chain as many grep commands as you like.  This allows you to filter the output of one grep command with a more specific pattern.&lt;br /&gt;&lt;br /&gt;grep has some more useful options as well:&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;grep -v pattern&lt;/span&gt;&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;the -v will search for "pattern" and show you the lines that DON'T match.  This is useful for ignoring lines.  For example, suppose you wanted to see all the hits to the signup.jsp page on your website that did NOT come from your company's firewall (say it's 4.2.2.1 for the sake of argument).&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:85%;" &gt;cat /var/log/httpd/access.log | grep "GET /signup.jsp" | grep -v 4.2.2.1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:78%;"&gt;10.1.1.1 - - [01/Apr/2007:18:22:48 -0700] "GET /signup.jsp HTTP/1.1" 200 4664 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11"&lt;br /&gt;192.168.0.1 - - [01/Apr/2007:18:23:08 -0700] "GET /signup.jsp HTTP/1.1" 200 4664 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11"&lt;/span&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Just for fun, lets use the "wc", or word count, command.&lt;br /&gt;&lt;tt&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:85%;" &gt;cat /var/log/httpd/access.log | grep "GET /signup.jsp" | grep -v 4.2.2.1 | wc -l&lt;/span&gt;&lt;br /&gt;2&lt;br /&gt;&lt;/tt&gt;&lt;br /&gt;&lt;br /&gt;So, we catted our access.log, piped it through grep for our signup URL, piped those results through grep to filter out lines containing our IP address, and piped that through word count to show the number of lines in the result.   We got two log lines that matched.&lt;br /&gt;&lt;br /&gt;This really is the tip of the iceberg for grep and what it can do for you in processing your logs.  I will follow up with part two in the coming days where I will cover more complex patterns and some shortcuts.  There are easier ways to do all of these examples, but this should help you to understand how it works and give you the tools to started using it today.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6554094098448561896-5317298263330819624?l=logtail.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://logtail.blogspot.com/feeds/5317298263330819624/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6554094098448561896&amp;postID=5317298263330819624' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/5317298263330819624'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/5317298263330819624'/><link rel='alternate' type='text/html' href='http://logtail.blogspot.com/2007/04/how-to-search-logs-using-grep-part-1.html' title='How to Search Logs Using grep, Part 1'/><author><name>Shaun</name><uri>http://www.blogger.com/profile/08447246104796576101</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6554094098448561896.post-5490546345577291387</id><published>2006-10-13T00:18:00.000-04:00</published><updated>2006-10-13T01:08:21.125-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='hp proliant debian sarge sata usb raid linux'/><title type='text'>Problems with New HP Proliant Servers and Debian Sarge</title><content type='html'>Recently, HP announced that it will be fully supporting Debian Sarge on its servers (&lt;a href="http://news.zdnet.com/2100-3513_22-6104891.html"&gt;http://news.zdnet.com/2100-3513_22-6104891.html&lt;/a&gt;) This is great news for the Debian community, of course, because a huge vendor stand behind it leads to some wonderful perks.  For those of us that would like to advocate Debian solutions, support here really goes a long way.&lt;br /&gt;&lt;br /&gt;Well, that's all good in theory, but I have to relate my recent real world experience here.  We planned on rolling out a new website on 4 new HP &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;Proliant&lt;/span&gt; &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;DL&lt;/span&gt;320 servers with &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;SATA&lt;/span&gt; hardware RAID.  This seemed like an excellent platform, until we actually started installing the latest and greatest copy of Debian 3.1 (Sarge) on it.  We ran into several problems.&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;1. The RAID containers were not recognized.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We could not get the system to install properly at all using the stock kernel here.   Once we managed to grab the latest kernel, we were able to install successfully.  Once we had a running system, however, we realized that the RAID containers were not recognized at all, and the driver in use was actually operating on the &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-corrected" id="SPELLING_ERROR_3"&gt;on board&lt;/span&gt; RAID card as if it were just a SCSI host bus adapter.  Writes to one disk were not mirrored... not good!&lt;br /&gt;&lt;br /&gt;A quick call to HP Linux support got us a very friendly and knowledgeable technician.  &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-corrected" id="SPELLING_ERROR_4"&gt;Unfortunately&lt;/span&gt;, he told us flat out that the hardware was not supported yet!  They were working furiously to get drivers ready for download, and that we'd probably be looking at December 2006 for the office support from HP.  He told us that the &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-corrected" id="SPELLING_ERROR_5"&gt;announcement&lt;/span&gt; took the support folks by surprise and they were not really in a good place to support all of the &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;Proliant&lt;/span&gt; hardware as promised.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;2. &lt;/span&gt;&lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_7"  style="font-size:130%;"&gt;USB&lt;/span&gt;&lt;span style="font-size:130%;"&gt; bus would not initialize properly.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We were left with a hung system during reboot as it attempted to load the USB modules.  Having purchased the HP remote management cards, and discovering that we are unable to use &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;USB&lt;/span&gt; under Linux, we were left with no choice but to disable the hardware and &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;USB&lt;/span&gt; support for these boxes.  This effectively made our management cards useless.  Our only option here was to basically wait out HP support or go with a 3rd party fix that the HP Linux support tech quietly managed to tell us about.&lt;br /&gt;&lt;br /&gt;So, HP left us in a tough spot here with these machines.  I have to say that their support team was extremely helpful and knowledgeable &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-corrected" id="SPELLING_ERROR_10"&gt;throughout&lt;/span&gt; the process.  I could definitely sense their frustration, though, at the premature &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-corrected" id="SPELLING_ERROR_11"&gt;announcement&lt;/span&gt;.  Hopefully, their software folks can get some stable drivers cranked out soon so they can make good on the promise of Linux support for the &lt;span onclick="BLOG_clickHandler(this)" class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;Proliant&lt;/span&gt; series.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6554094098448561896-5490546345577291387?l=logtail.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://logtail.blogspot.com/feeds/5490546345577291387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6554094098448561896&amp;postID=5490546345577291387' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/5490546345577291387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/5490546345577291387'/><link rel='alternate' type='text/html' href='http://logtail.blogspot.com/2006/10/problems-with-new-hp-proliant-servers.html' title='Problems with New HP Proliant Servers and Debian Sarge'/><author><name>Shaun</name><uri>http://www.blogger.com/profile/08447246104796576101</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6554094098448561896.post-4629044213228246538</id><published>2006-10-10T21:54:00.000-04:00</published><updated>2006-10-13T00:16:35.550-04:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='uptime disaster recovery network availability raid prevention reliability redundancy monitoring logwatch nagios augur Netcool disaster contingency change backup  Maintenance'/><title type='text'>Strategies for Improving Network Uptime</title><content type='html'>&lt;!-- &lt;a href="http://www.digg.com"&gt;&lt;br /&gt;&lt;img src="http://digg.com/img/badges/80x15-digg-badge.gif" width="80" height="15" alt="Digg!" /&gt;&lt;/a&gt; --&gt;&lt;br /&gt;&lt;br /&gt;Improving your network uptime is one of the top goals of every network administrator and should, like everything else, be approached in a systematic way.  It doesn't matter how good you are or how much experience you've got.  If you're not paying attention to your the weaknesses in your network, your reliability will quickly erode.&lt;br /&gt;&lt;br /&gt;You should have 3 basic goals in mind when looking at improving your uptime:&lt;br /&gt;&lt;br /&gt;Goal 1.  Prevention.  Prevent problems from happening in the first place.&lt;br /&gt;Goal 2. When a problem does come up, work towards a fast resolution.&lt;br /&gt;Goal 3. Accurate Planning.  Plan your changes.  Test them as needed.&lt;br /&gt;&lt;br /&gt;With those goals in mind, here are some good practices that can help improve network uptime:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;1. Look for single points of failure&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Reducing or eliminating single points of failure on your network goes a long way to increasing reliability.  Good network design aside, daisy chaining switches is a good example where an unnecessary point of failure has been introduced.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;2. Pay attention to failure rates and implement redundancy where it makes sense&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All too often, network administrators beef up redundancy in the wrong places.   What good is adding a redundant firewall to your network if your critical app is sitting on a 10 year old desktop with an IDE hard drive?  The failure rate of the firewall is a tiny fraction compared to that old server.&lt;br /&gt;&lt;br /&gt;Within servers, disk drives, power supplies and other devices with moving parts are the best place to start looking for high failure rates.   Servers themselves have an overall failure rate, and should also be considered candidates for redundancy if the app is critical enough.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;3. Monitor your network&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Each component of the network should be actively monitored.  Monitoring is a subject in itself, but for now, the key things to be looking at are a combination of ping and real-time log processing/alerting.  This allows you to respond to disk failures, fried switch ports and most anything else that can fail.  Traditionally, I have also monitored device statistics such as CPU, memory, disk space, etc., setting key thresholds to alert me if anything is out of the ordinary.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.logwatch.org/"&gt;Logwatch&lt;/a&gt;&lt;br /&gt;&lt;a href="http://nagios.org/"&gt;Nagios&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.augursystems.com/"&gt;Augur&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www-306.ibm.com/software/tivoli/welcome/micromuse/"&gt;Netcool&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;4. Perform regular walkthroughs&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;While you can catch a lot of issues through a good monitoring software implementation, there's no substitute for physically observing your network.  Error lights, overloaded UPS beeps, overtemp alarms and who knows what else are sometimes only directly observable.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;5. Keep your network neat&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is very often overlooked.   The catch here is that it is extremely easy to yank the wrong cable, power off the wrong server or even trip and fall, possibly taking down your whole network!  Even if you're exceedingly careful, a disorganized network takes significantly longer to troubleshoot and repair when the pressure is on.&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Label and tie all cables&lt;/li&gt;&lt;li&gt;Have an up-to-date network map posted&lt;/li&gt;&lt;li&gt;Label all servers front and back&lt;/li&gt;&lt;li&gt;Always mount hardware properly and use cable management features&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;6. Document it&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There isn't much to say here.  We all let documentation slide sometimes... that's human nature.  But its not hard to see how accurate docs lead to faster problem resolution.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;7. Build contingency/disaster recover plans&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;Having a solid plan in place to recover from the loss of each component of the network helps to speed up recovery time.  Probably more importantly, however, is the insight gained through the process.  Often, this process lights up need for critical spares and replacement parts well before they are actually needed.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;8. Use change control&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This one has been batted around a lot, but it comes down to a few simple concepts.&lt;br /&gt;1. Don't make changes to production systems without planning them.&lt;br /&gt;2. Get others involved that may be impacted by those changes so they can have their concerns met.&lt;br /&gt;3. Plan your exit strategy each step of the way, in case of both success and failure.&lt;br /&gt;&lt;br /&gt;Really, there are books out there on change control, but what's important here are those key concepts.  Your plan can be a fully prepared form with multiple signoffs, or just a (carefully!) noted checklist on scrap paper... what's important is that you follow it.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;9. Maintain warantees and service contracts&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If HP will have a guy onsite in 4 hours to replace your failed CPU, you could have called them 10 minutes in.  If you are using custom-built hardware, seek out onsite service options or plan on keeping a full set of spares around.  Nothing beats knowing you have replacement parts available or on the way so you can give 100% of your focus to migrating services, managing user expectations, etc.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;10. Maintain backups&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Backups are key to getting your data back quickly and effectively.   A combination of online and archival backup techniques help you attack those big disaster risks.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;"&gt;11. Simplify&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Complex networks lead to complex problems.  Your network should be as simple as possible while meeting the needs for future growth.   For example, if you retire a bunch of VLAN on your network, clean up your switch configs.&lt;br /&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;&lt;br /&gt;12. Use maintenance windows&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You should plan to do your maintenance in a maintenance window.  It sounds like common sense, but it's one of the best ways to cut down on surprises.  And, depending on who your customer is and what the app requirements are, you can often agree to exclude planned maintenance windows from your uptime guarantees.&lt;br /&gt;&lt;br /&gt;A lot of the practices on this list sound like common sense, and as well they should!  Many common IT best practices come into play when talking about network availability and server uptime.  If you are optimizing for uptime, however, you should consider them as key points to consider.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6554094098448561896-4629044213228246538?l=logtail.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://logtail.blogspot.com/feeds/4629044213228246538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6554094098448561896&amp;postID=4629044213228246538' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/4629044213228246538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6554094098448561896/posts/default/4629044213228246538'/><link rel='alternate' type='text/html' href='http://logtail.blogspot.com/2006/10/strategies-for-improving-network-uptime.html' title='Strategies for Improving Network Uptime'/><author><name>Shaun</name><uri>http://www.blogger.com/profile/08447246104796576101</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
