The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-22-2007
porter porter is offline
Registered User
 

Join Date: Jan 2007
Posts: 2,965
You need backquotes to capture output
Then double quotes to make it a single argument for test
And you need test
And it should be a truely empty string

Code:
if test "`cat /var/log/messages | grep fail`" = ""  
then 
echo "Good"
else
echo "Bad"
fi
alternatively use

Code:
if test -z "`cat /var/log/messages | grep fail`" 
...
But you could get rid of all the above with

Code:
if grep fail /var/log/messages
then
     echo failed
else
     echo no problems
fi
Reply With Quote