The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
one simple shell script problem shaloovia Shell Programming and Scripting 7 04-21-2009 03:02 PM
problem with (probably) grep in shell script proxy_ UNIX for Dummies Questions & Answers 1 01-10-2009 05:47 PM
simple shell - how to get a parameter typed in a shell script cmitulescu Shell Programming and Scripting 4 01-09-2009 08:45 PM
simple shell script problem djt0506 UNIX for Dummies Questions & Answers 2 12-07-2005 12:00 AM
Simple ksh script problem Warrior232 Shell Programming and Scripting 14 09-10-2005 12:11 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-16-2009
mak_boop mak_boop is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 5
Problem with IF - CAT - GREP in simple shell script

Hi all,

Here is my requirement

I have to search 'ORA' word in out.log file,if it is present then i need to send that file (out.log) content to some mail id.If 'ORA' word is not in that file then i need to send 'load succesful' message to some mail id.

The below the shell script is not giving expected result.Please help me to get correct script



Code:
if [{cat out.log | grep -c "ORA"}  -eq  1]
then
echo out.log
   exit 0
 else
   echo "Load Succes"
fi


Regards
Mak

Last edited by Neo; 07-16-2009 at 08:26 AM.. Reason: code tags
  #2 (permalink)  
Old 07-16-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474

Code:
grep -c "ORA" outlog 1>/dev/null

if [ $? -eq 0 ]  ## some oracle error
then
echo out.log  
######## can mail to the user 
   exit 0
 else
   echo "Load Succes"
###### can mail to the user 
fi

check the mail command and it's option.
  #3 (permalink)  
Old 07-16-2009
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
Quote:
Originally Posted by panyam View Post
Code:
grep -c "ORA" outlog 1>/dev/null

if [ $? -eq 0 ]  ## some oracle error
then
echo out.log  
######## can mail to the user 
   exit 0
 else
   echo "Load Succes"
###### can mail to the user 
fi

check the mail command and it's option.
Hi Panyam,

Your script is nice. But instead of

grep -c "ORA" outlog 1>/dev/null

You can use

grep -q "ORA" outlog


This has the advantage that it will not write any thing on standard out put so no re-direction is required. Also it will exit with success on the first occurance of "ORA", will not search file till the end which is not required.
  #4 (permalink)  
Old 07-16-2009
rakeshawasthi rakeshawasthi is offline
Registered User
  
 

Join Date: Aug 2004
Location: India
Posts: 379
Quote:
Originally Posted by ranjithpr View Post
Hi Panyam,

Your script is nice. But instead of

grep -c "ORA" outlog 1>/dev/null

You can use

grep -q "ORA" outlog


This has the advantage that it will not write any thing on standard out put so no re-direction is required. Also it will exit with success on the first occurance of "ORA", will not search file till the end which is not required.
This is interesting... I would suggest using -w option also i.e. grep -q -w to make sure ORA is the same as we want.
  #5 (permalink)  
Old 07-16-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Quote:
Originally Posted by ranjithpr View Post
Hi Panyam,

Your script is nice. But instead of

grep -c "ORA" outlog 1>/dev/null

You can use

grep -q "ORA" outlog


This has the advantage that it will not write any thing on standard out put so no re-direction is required. Also it will exit with success on the first occurance of "ORA", will not search file till the end which is not required.

Thanks Ranjith for the efficient idea
  #6 (permalink)  
Old 07-16-2009
mak_boop mak_boop is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 5
thanks a lot Panyam
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0