Tuesday 11 November 2008

Don't grep grep

A useful tool in scripting is the "grep" function. This program will find a string in a file. It is often used also to find if a process is running:

ps ax | grep sendmail

That command will find if sendmail is running. The problem is that you might end up with an other entry for this command. Because you grep for "sendmail", you may well end up with this command showing because the "sendmail" string is in the command line. To avoid that, you can use the -v flag to grep:

ps ax | grep sendmail | grep -v grep

That command will find all the lines in the current process list that have the "sendmail" string in it, and will remove the lines containing the string "grep".

Reference : Suse Linux - 100 tips and tricks by Patrick Lambert

0 comments:

by TemplatesForYouTFY
SoSuechtig