Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call awk in shell script...

Status
Not open for further replies.

rajeshtektips

Programmer
Nov 7, 2005
7
US
Hi ,

I am invoking awk in shell script and its giving the below error..

syntax error The source line is 7.
The error context is
$ORACLE_HOME/bin/sqlldr >>> safety/safety@ <<<
awk: The statement cannot be correctly parsed.
The source line is 7.
syntax error The source line is 12.

Please find below the code

#!/bin/sh
# Title load_compman.sh
# Purpose To load safety data into the database
# DB/Schema Metrics/safety
# Dependencies Sqlloader controlfile : load_data.ctl,
# Database Procedure : wc_dbload
# ==========================================================
#
#--- Set the environment
ORACLE_HOME=/u00/app/oracle/product/9.2.0; export ORACLE_HOME
ORACLE_SID=dwhdev; export ORACLE_SID
TNS_ADMIN=/etc; export TNS_ADMIN
CUR_DT=`date +"%m%d%Y%H%M"`; export CUR_DT

COMPMAN_TOP=/home/safety/safety/development; export COMPMAN_TOP
SCRIPT_DIR=$COMPMAN_TOP/scripts; export SCRIPT_DIR
DATA_DIR=$COMPMAN_TOP/incoming; export DATA_DIR
DATA_DIR_MAJ=$COMPMAN_TOP/incoming_majestic; export DATA_DIR_MAJ
LOG_DIR=$COMPMAN_TOP/log; export LOG_DIR
BACKUP_DIR=$COMPMAN_TOP/backup; export BACKUP_DIR
#--------------------------------------------------------------
#--- Check for the presence of Signal files and process

if test -f $DATA_DIR/*.dat
then
cat $DATA_DIR/*.dat > $DATA_DIR/incoming.out

$ORACLE_HOME/bin/sqlldr safety/safety@dwhdev.world \
control=$SCRIPT_DIR/load_config_compman.ctl \
bad=$SCRIPT_DIR/incoming.bad \
log=$LOG_DIR/incoming.log

mv $DATA_DIR/*.dat $BACKUP_DIR
cp $DATA_DIR/incoming.out $BACKUP_DIR/incoming$CUR_DT.out
rm $DATA_DIR/incoming.out

#--- Load data to Claim table

$ORACLE_HOME/bin/sqlplus safety/safety@dwhdev.world <<EOF
-- Should we spool the log or output ?
execute wc_dbload ('ALL');
-- spool off
EOF

else
echo '****** No records from the Signal customer ******' >> $LOG_DIR/incoming.log
fi

$ORACLE_HOME/bin/sqlplus -s safety/safety@dwhdev.world @$SCRIPT_DIR/verify_load >> $LOG_DIR/incoming.log

cat $LOG_DIR/incoming.log > $LOG_DIR/inbox_status
mailx -m -s "Safety data process status for `date`" xxxx@xxx.com < $LOG_DIR/inbox_status

cp $LOG_DIR/inbox_status $BACKUP_DIR/inbox_status$CUR_DT
cp $LOG_DIR/incoming.log $BACKUP_DIR/incoming_$CUR_DT.log

rm $LOG_DIR/inbox_status
rm $LOG_DIR/incoming.log

#--- Check for the presence of Majestic files and process




if test -f $DATA_DIR_MAJ/*.TXT
then
cat $DATA_DIR_MAJ/*.* > $DATA_DIR_MAJ/incoming_maj.out

awk '
{ prov = $1;FS = "|"
if (prov == 'MAJESTIC')

{

$ORACLE_HOME/bin/sqlldr safety/safety@dwhdev.world \
control=$SCRIPT_DIR/load_config_compman.ctl \
bad=$SCRIPT_DIR/incoming_maj.bad \
log=$LOG_DIR/incoming_maj.log

mv $DATA_DIR_MAJ/*.dat $BACKUP_DIR
cp $DATA_DIR_MAJ/incoming_maj.out $BACKUP_DIR/incoming_maj$CUR_DT.out
rm $DATA_DIR_MAJ/incoming_maj.out

#--- Load data to Claim table

$ORACLE_HOME/bin/sqlplus safety/safety@dwhdev.world <<EOF
-- Should we spool the log or output ?
execute wc_dbload ('ALL');
-- spool off
EOF

$ORACLE_HOME/bin/sqlplus -s safety/safety@dwhdev.world @$SCRIPT_DIR/verify_load >> $LOG_DIR/incoming_maj.log

cat $LOG_DIR/incoming_maj.log > $LOG_DIR/inbox_status_maj
mailx -m -s "Safety data process status for `date`" xxxx@xxx.com < $LOG_DIR/inbox_status_maj

cp $LOG_DIR/inbox_status_maj $BACKUP_DIR/inbox_status_maj$CUR_DT
cp $LOG_DIR/incoming_maj.log $BACKUP_DIR/incoming_maj_$CUR_DT.log

rm $LOG_DIR/inbox_status_maj
rm $LOG_DIR/incoming_maj.log

exit }
else
{
$ORACLE_HOME/bin/sqlldr safety/safety@dwhdev.world \
control=$SCRIPT_DIR/load_majestic.ctl skip 1\
bad=$SCRIPT_DIR/incoming_maj.bad \
log=$LOG_DIR/incoming_maj.log

mv $DATA_DIR_MAJ/*.dat $BACKUP_DIR
cp $DATA_DIR_MAJ/incoming_maj.out $BACKUP_DIR/incoming_maj$CUR_DT.out
rm $DATA_DIR_MAJ/incoming_maj.out

#--- Load data to Claim table

$ORACLE_HOME/bin/sqlplus safety/safety@dwhdev.world <<EOF
-- Should we spool the log or output ?
execute wc_dbload_new ('ALL');
-- spool off
EOF

$ORACLE_HOME/bin/sqlplus -s safety/safety@dwhdev.world @$SCRIPT_DIR/verify_load >> $LOG_DIR/incoming_maj.log

cat $LOG_DIR/incoming_maj.log > $LOG_DIR/inbox_status_maj
mailx -m -s "Safety data process status for `date`" xxxx@xxx.com < $LOG_DIR/inbox_status_maj

cp $LOG_DIR/inbox_status_maj $BACKUP_DIR/inbox_status_maj$CUR_DT
cp $LOG_DIR/incoming_maj.log $BACKUP_DIR/incoming_maj_$CUR_DT.log

rm $LOG_DIR/inbox_status_maj
rm $LOG_DIR/incoming_maj.log

exit }

}' incoming_maj.out


#--- Load data to Claim table

else
echo '****** No records from the Majestic customer ******' >> $LOG_DIR/incoming_maj.log
fi

$ORACLE_HOME/bin/sqlplus -s safety/safety@dwhdev.world @$SCRIPT_DIR/verify_load >> $LOG_DIR/incoming_maj.log

cat $LOG_DIR/incoming_maj.log > $LOG_DIR/inbox_status_maj
mailx -m -s "Safety data process status for `date`" xxxx@xxx.com < $LOG_DIR/inbox_status_maj

cp $LOG_DIR/inbox_status_maj $BACKUP_DIR/inbox_status_maj$CUR_DT
cp $LOG_DIR/incoming_maj.log $BACKUP_DIR/incoming_maj_$CUR_DT.log

rm $LOG_DIR/inbox_status_maj
rm $LOG_DIR/incoming_maj.log

exit
 
You expect awk will execute shell instructions ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry, I am new to awk and shell program. I was modifying the existing coding using awk function...and I don't know awk will execute shell instructions or not.

Please let me know whether it can be possible or not..and how?

Thanks
Raj
 
for each variable you wish to pass to awk you will need to do something like

Code:
 awk -v ORACLE_HOME=$ORACLE_HOME ' {script} '

awk doesn't use the $ syntax, so if you wanted to
Code:
 print "${ORACLE_HOME}/bin/sqlldr safety/safety@dwhdev.world \"

it would be
Code:
 print ORACLE_HOME "/bin/sqlldr safety/safety@dwhdev.world \"
to execute shell commands use

Code:
 system("cp /filename")

or checkout getline in the docs

arodef
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top