RE: ** UNIX shell -- grep behavior different

From: A Joshi <ajoshi977_at_yahoo.com>
Date: Sun, 28 Nov 2010 20:51:37 -0800 (PST)
Message-ID: <754073.16414.qm_at_web57503.mail.re1.yahoo.com>



here is what I did
created another shell script to just do the

grep -i created $flist
grep -i created $flist > $mlist

#mailx

it worked fine. there were 14 'created' lines in both $flist $mlist . all okay. So looks like it was some issue with $flist not getting closed or something like that.

so now I have separated the Main shell script into two parts. two different shell scripts

script one

. /opt/oracle/scripts/setenv
cd /opt/oracle/scripts

DBS=/opt/oracle/scripts/dbs
flist=/opt/oracle/scripts/new_obj.log
mlist=/opt/oracle/scripts/mail_new_obj.log echo ' '> $flist
echo ' '> $mlist

cat $DBS | while read DB
do
sqlplus db_ro_at_$DB @new_objects.sql <.pw >> $flist done

script two
. /opt/oracle/scripts/setenv
cd /opt/oracle/scripts

flist=/opt/oracle/scripts/new_obj.log
mlist=/opt/oracle/scripts/mail_new_obj.log

grep -i created $flist > $mlist

#mailx

Main script calls these two in order .everything is fine now.

  • On Sun, 11/28/10, A Joshi <ajoshi977_at_yahoo.com> wrote:

From: A Joshi <ajoshi977_at_yahoo.com>
Subject: RE: ** UNIX shell -- grep behavior different To: oracle-l_at_freelists.org
Date: Sunday, November 28, 2010, 3:27 PM

Jared

I added set -v but it is not giving any additional information which grep from both shell script, UNIX interactive session gives same output /bin/grep

+ which grep
/bin/grep
I also hardcoded /bin/grep
but still it is same behavior
 
Mark
 the first. is to set the environment. I'm using the same for interactive session. I plan to expand this for other database info to be checked every day/week. cat /opt/oracle/scripts/dbs
DBST1
DBST4
right now I'm just going to copy another existing shell script with different steps and make changes and see if that works.instead of struggling with this. --- On Sat, 11/27/10, Mark W. Farnham <mwf_at_rsiz.com> wrote:

From: Mark W. Farnham <mwf_at_rsiz.com>
Subject: RE: ** UNIX shell -- grep behavior different To: jkstill_at_gmail.com, ajoshi97_at_yahoo.com Cc: rajendra.pande_at_ubs.com, oracle-l_at_freelists.org Date: Saturday, November 27, 2010, 1:43 PM

The contents of the file you’re dotting right at the top and echoing the path and arguments might also be useful in debugging this.  
Writing a “hello world” harness and just always using that as your wrapper is probably useful in the long haul for things that actually need to be done with scripts.  
Differences in the processing of certain escape characters between the interactive shell \(  \) are possible depending on the shell, but the aforementioned different path seems more probable; adding a whence (or which) grep might also be useful.  
OR, since you have database software, create a DBA datawarehouse, make a table and insert into it from all the databases you’re monitoring. Then just write a select. Parsing stuff in scripts is fine when you need to, but why bother when the database would be a good place to stash your data so you can slice and dice it arbitrarily in the future.  
For the purpose you’re after, Rightsizing, Inc. marketed something called EXTMON in the mid 1990’s, that tracks creation and extension of all the objects in a database. Since it was a clear text set of scripts, people generally ignored the copywrite and we stopped keeping it current. You can probably find it or a copy out there somewhere. You’ll probably have to change a few things to make it worth comprehensively for 11g.  
Several of our clients used reports off that history to plan capital acquisition of disk space.  
mwf
 

From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Jared Still Sent: Saturday, November 27, 2010 1:20 PM To: ajoshi97_at_yahoo.com
Cc: rajendra.pande_at_ubs.com; oracle-l_at_freelists.org Subject: Re: ** UNIX shell -- grep behavior different  

On Fri, Nov 26, 2010 at 7:17 PM, A Joshi <ajoshi977_at_yahoo.com> wrote:

 

set -x

 

you might try adding set -v here for troubleshooting purposes

 

grep -i created $flist
grep -i created $flist > $mlist

 

If you run the script, then run the grep from the command line against this

file ($mlist), the grep finds all the values you expect?

 

To paraphrase Inigo Montoya "I don't think you're using the grep you think you're using"

 

Try hardcoding the full path for grep, which is usually a good idea in shell scripts anyway.

 

Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist Oracle Blog: http://jkstill.blogspot.com Home Page: http://jaredstill.com

        

--
http://www.freelists.org/webpage/oracle-l
Received on Sun Nov 28 2010 - 22:51:37 CST

Original text of this message