RE: awk and ksh question - solved

2003-02-04 Thread Koivu, Lisa
Title: RE: awk and ksh question - solved





Stephen, I'm aware of the syntax. My question was, WHY?? Robert hit it on the head, awk and ksh are both interpreting $1. 

Anyway I solved the problem with shift, like this. Thanks to all that replied. 


export PAGER=
export PAGERFILE=dba_oncall.txt
export FILE_TO_SEND=$1
shift ;


if [[ $# = 1 ]] 
then


export SUBJECT=Subject: $1;
print $SUBJECT  $$.log
shift ;


fi;



cat $FILE_TO_SEND  $$.log


for PAGER in ${*-$(awk '!/^#/ {print $1}' dba_oncall.txt)};
do 


 print $PAGER 
 sendmail $PAGER  $$.log



done 


-Original Message-
From: Stephen Lee [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 03, 2003 5:49 PM
To: Multiple recipients of list ORACLE-L
Subject: RE: awk and ksh question




$number to awk means the number-th field.
To pass variables into an awk statement, you generally have two choices:


1. The ugly one where you do a bunch of stuff with double and single
quotes.


2. The correct one where you do something like


/usr/bin/nawk 'statement AWKVAR1 more statement AWKVAR2' AWKVAR1=$THIS
AWKVAR2=$THAT
where THIS and THAT are shell variables (such as $1 and $2).


Example:
export X=HELLO
echo SDFLKJ | nawk '{print Y}' Y=$X
HELLO


Note that you do NOT use $Y in the awk script; just Y.



-Original Message-
Sent: Monday, February 03, 2003 3:29 PM
To: Multiple recipients of list ORACLE-L



Hello everyone, 
I'm trying to awk through a text file and use that with a passed-in message
to send email. Here's an example of my text file:
# DBA's on call 
[EMAIL PROTECTED] # Lisa pager 
[EMAIL PROTECTED] # Lisa email 
Here's my awk statement, which works properly 
awk '!/^#/ {print $1}' filename.txt 
prints the first entry in each file and skips any lines starting with #. 
So I put it in a loop. I don't quite understand all the syntax here, I'm
pulling the exact syntax out of Steve Adams' database check script. 
-- 
for PAGER in ${*-$(awk '!/^#/ {print $1}' dba_oncall.txt)} 
do 
print $PAGER 
done 
-- 
Works fine. 



Now when I try to pass in a parameter in $1 (which I mean to be the email
message), awk grabs it and the script no longer works. Like this


-- 
export FILE=$1 
print File is $FILE 
for PAGER in ${*-$(awk '!/^#/ {print $1}' dba_oncall.txt)}; 
do 
print $PAGER 
done 
-- 
This prints the name of the file in both print statements, before and inside
the loop. What am I doing wrong? 



Also if anyone can explain in a nutshell what the ${} means (I think it
means consider the results as a variable) and the * and - and $() means in
the for/do loop syntax I would be grateful. I'm leafing through my ksh book
but I think this is several specific functions all slapped together. 
Thanks to anyone that can help pull my head out of the sand... 
Lisa Koivu 
Oracle Database Administrator 
Fairfield Resorts, Inc. 
5259 Coconut Creek Parkway 
Ft. Lauderdale, FL, USA 33063 
Office: 954-935-4117 
Fax: 954-935-3639 
Cell: 954-683-4459 
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Stephen Lee
 INET: [EMAIL PROTECTED]


Fat City Network Services -- 858-538-5051 http://www.fatcity.com
San Diego, California -- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from). You may
also send the HELP command for other information (like subscribing).





RE: awk and ksh question - solved

2003-02-04 Thread Stephen Lee

-Original Message-
awk and ksh are both interpreting $1. 
-

Not possible.  One or the other will see $1, but not both.  That's the
problem with using quotes instead of assigning things to awk variables -- It
makes reading the stuff confusing.

FWIW, here is what I do:

   ## See if there is anything to send
   COUNT=`awk '/^$/ {next}; END {print NR}' $PAGE_FILE`
   ## If so send it
   if [ $COUNT -gt 0 ]; then
  PAGER_PERSON=''
  cat ${ADMIN_DIR}/who_to_page | while read LINE; do
 PAGER_PERSON=${PAGER_PERSON},${LINE}
  done
  ## Optional cleanup lines for the intractably paranoid
  PAGER_PERSON=`echo $PAGER_PERSON | sed 's/[   ]*//g'`
  PAGER_PERSON=`echo $PAGER_PERSON | sed 's/^,*//g'`
  PAGER_PERSON=`echo $PAGER_PERSON | sed 's/,,*/,/g'`
  if [ -n $PAGER_PERSON ]; then
 mailx -s IT IS ALL OVER THE WALLS $PAGER_PERSON  $PAGE_FILE
  fi
   fi
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Stephen Lee
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).




RE: awk and ksh question - solved

2003-02-04 Thread Stephen Lee

I thought I should add, if you wanted to comment out people in your pager
list, you could do something like:

sed 's/^[   ][]*//g; /^#/d' ${ADMIN_DIR/who_to_page | while read
LINE; do
 PAGER_PERSON=${PAGER_PERSON},${LINE}


Note: The brackets in the sed statement have a space and a tab in them to
handle the paranoia factor.

 -Original Message-
 FWIW, here is what I do:
 
## See if there is anything to send
COUNT=`awk '/^$/ {next}; END {print NR}' $PAGE_FILE`
## If so send it
if [ $COUNT -gt 0 ]; then
   PAGER_PERSON=''
   cat ${ADMIN_DIR}/who_to_page | while read LINE; do
  PAGER_PERSON=${PAGER_PERSON},${LINE}
   done
   ## Optional cleanup lines for the intractably paranoid
   PAGER_PERSON=`echo $PAGER_PERSON | sed 's/[   ]*//g'`
   PAGER_PERSON=`echo $PAGER_PERSON | sed 's/^,*//g'`
   PAGER_PERSON=`echo $PAGER_PERSON | sed 's/,,*/,/g'`
   if [ -n $PAGER_PERSON ]; then
  mailx -s IT IS ALL OVER THE WALLS $PAGER_PERSON 
  $PAGE_FILE
   fi
fi
 -- 
 Please see the official ORACLE-L FAQ: http://www.orafaq.net
 -- 
 Author: Stephen Lee
   INET: [EMAIL PROTECTED]
 
 Fat City Network Services-- 858-538-5051 http://www.fatcity.com
 San Diego, California-- Mailing list and web hosting services
 -
 To REMOVE yourself from this mailing list, send an E-Mail message
 to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
 the message BODY, include a line containing: UNSUB ORACLE-L
 (or the name of mailing list you want to be removed from).  You may
 also send the HELP command for other information (like subscribing).
 
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Stephen Lee
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).




RE: awk and ksh question - solved

2003-02-04 Thread Stephen Lee
 -Original Message-
 Those are the companies that you'd use the $HOME/.mailrc for.
 
-

Ah yes  TMTOWTDI

Since I have multiple scripts that do things and monitor things, the list of
mail and/or pager recipients is different for different things, even within
a single script. As a general philosophy on scripting, I like to keep things
as self-contained as reasonably practical.  I think this reduces the Murphy
Factor; and it makes it more obvious, when going to a directory for a
script, after not looking at the script for months, what stuff is required
for the script to do its thing -- it's all right there in that directory.
So I usually put larger scripts along with their config files in their own
directory.

If there are variables that we know we want to share among all scripts
regardless of who wrote the script, we keep those in a file called
ORACLE_VARIABLES (imaginative name, huh?).  And one of those variables is a
list of mail recipients for scripts that want to send to that list of
recipients.  The script code for pulling that list out of the text file is
very simple.

TMTOWDI.
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Stephen Lee
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).