Grep How To - Part 1

February 7th, 2007

Here are a few little tid bits that I use on a daily basis with the awesome Grep command line tool.

Grep allows you to search files for symbols or strings (groups of characters like words) and will return the files that the search sting is found in. For example you want to search a website’s access log file for a recent traffic that came from a search engine. Most search engine referral urls have a question mark in them. The Grep command would look something like this:

grep [search string] [file name]

grep “?” /www/logs/golod.com-access.log

I use the double quotes around the question mark so that grep doesn’t get confused by a symbol, the third part is the location of the file on my server that I want to search.

Now let’s say you get a slew of information and you really only want to see searches that came in on a specific date. Since apache is configured to format my log files with a date like 07/Feb as the date I would “pipe” the results or pass them to another grep command. This looks like:

grep [search string] [file name] | grep [2nd search string]

grep “?” /www/logs/golod.com-access.log | grep “07/Feb”

This essentially passes the results of the first grep search to the 2nd grep search for further refinement.

One last thing that I use all of the time with Grep is the -v operator. Adding -v to your grep statement allows you to eliminate results that match a certain search string. Using our example:

grep [search string] [file name] | grep [2nd search string] | grep -v [search string]

grep “?” /www/logs/golod.com-access.log | grep “07/Feb” | grep -v “yahoo”

This would give us the same results as before, but it would remove any of the results that had the string yahoo anywhere in them.

Hopefully, this helps.

tags: , , ,

Ubuntu Linux How-To Part Two

January 19th, 2007

Well, I managed to spend most of last weekend on the linux project as well as the Windows Small Busniess Server 2003 project. My first move was to take the Debian Sarge installation drive from my development linux box and place it into a new Asus Terminator C3 barebones system as the resources it requires can be addressed more than adequately by the Terminator C3 with 512MB of RAM. That went AS PLANNED and we always like when things go as we plan them, right? Well, the same cannot be said about my Ubuntu LTS installation attemps on another Terminator C3. I tried a number of different installation discs (as I first thought that it was a bad CD-R), but was not able to get the install to work.

So, I decided that I would try my Debian (Sarge release) net install CD I had lying around. Sure enough, it installed just fine. After spending more than an hour on this, I didn’t really see any reason why I needed to work more on getting Ubuntu installed (even though I would really like to check out what all of the hype is about), especially since it is Debian based. Debian has RDesktop (a linux RDP client for windows terminal server installs or Windows XP Pro installations) built in with the default. Since I was planning on using this machine as a “thin client” to log into a remote server to run my applications, this was good enough.

Well, this is where my lack of real Linux knowledge was my downfall. I wanted to log in to my remote server, no problem. I needed to change the resolution on my monitor, but I did not have the proper video driver installed. Ok, this is the internet age. So, I head over to the ASUS site and grab their 4-in-1 Linux drivers for the C3. Oh, they don’t exist on their site? Hmmm. Well, I did find some instructions on installing someone else’s home grown C3 display drivers, but I didn’t know how to follow along as none of the docs covered Debian installs.

So, I bit the bullet and put Windows 2000 Pro on the box and called it a day. I did however find that there are linux display drivers on the driver CD that comes with the Terminator C3 and I do need to try that out. I may build another one to just act as my “Linux learning box” to actually get on the linux team. I can’t use the dev box as an experimentation box right now as I am running some stuff on there that I use everyday for my business.

tags: , , , ,

My Linux How To

January 12th, 2007

Welcome aboard. This new sub-site is going to chronicle my foray into using Linux as my desktop Operating System of choice.  I am not sure that I will be happy all of the time, as I like all of my windows applications, but I am going to give it a shot for a number of reasons.

First, it is not as much of a resource hog as Windows is and I am going to be building a couple of Linux machines on some super-cheap ASUS Terminator barebones systems.  They will cost me $79 +shipping each and I will have to throw some “old” SDRAM and a hard drive into them. Other than that, they are ready to go, with an 800MHz Via processor and all. I will be putting Ubuntu Linux on these and using the RDesktop application to Remote Desktop into a windows 2003 Small Business Server.  Hopefully, this will work as well as I expect.

Secondly, it is free. Not that I cannot afford to buy Microsoft OSes, I just like the idea of a “free” open source system that has thousands of people contributing to it every day.  Linux has been around for many, many years and is running the vast majority of web servers out there today. So, it is clearly up to the task of running some dumpy desktop boxes for me.

Lastly, I am a rookie PHP programmer and I want to do more scripting with PERL and Python in the coming years, so why not make it easier to do so, by running the same system that all of my web server boxes run?

I will be posting updates, tips and how-to’s for Linux installation, administration and day-to-day use. Hopefully, I will learn enough that I will have something to post here.

tags: , , ,