i am trying to do a unix script and this is my first time getting in touch with unix.
i am trying to query and execute the following:
touch $dir/emailList.txt
set final = $dir/emailList.txt
#construct SQL statement
$DCITS_SQL << SQLSTAT
set line=(select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN);
SQLSTAT
while read ($line)
#pipe the output to while read
do
if ["$line"]#check if line is not null
then #if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo '$fin,$name,$gway' >> $final
endif
done
i keep having the error "line=undefined variable". any one know whats wrong with the above? many thanks in advance!
i tried piping the whole thing to while read but there are still some errors:
#construct SQL statement
{$DCITS_SQL << EOF
set head off
select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN;
exit
EOF
}|while read line
do
if ["$line"]#check if line is not null
then #if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo '$fin,$name,$gway' >> $final
endif
done
{
$DCITS_SQL << EOF
set head off
select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN;
exit
EOF
}|while read line
do
if [ "$line" ] #check if line is not null
then
#if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo "$fin,$name,$gway" >> $final #changing single quotes to double
fi # not endif
done
hi!
the sql is finally returning something but the while loop is still not working...
error message:
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
}: Command not found
while: Expression syntax
Without the -s option, you will get display like this while connecting
and display like this while disconnecting,
With the -s option, this display gets surpressed. It is basically used in scripts to get only the sql statement output and to avoid all unwanted information.
If you can check the script that your '$DCITS_SQL' points to, you will be able to determine if that is the cause.
========================================================
SQL*Plus: Release 9.2.0.5.0 - Production on Mon Apr 30 10:10:42 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
sorry but i dunno whether its the sql the cause of the error because the database is returning the results but its the while loop having error...
kindly advise...thanks!
==========================================================
{$DCITS_SQL << EOF
set head off
select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN;
exit
EOF} | while read line
do
if [ "$line" ]#check if line is not null
then #if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo "$fin,$name,$gway" >> $final
fi
done
Is this the entire piece of code that you are running? Where is the variable "$final" initialised? Please change the below in the code
EOF} | while read line
to
EOF
} | while read line
I hope you are doing that. If you have additional code other than this, check if the error has something to do with that. If you donot use the '-s' option, you have to handle the information that comes from the sqlplus. Otherwise, it could give confusing results. Otherwise, you can spool the output of the sql to a file.
set head off
spool $filename
select .......
spool off
exit
This will have the entire output of the sql in that file and you can try to manipulate that file. Check and see what suits you best.
i tried but its still not running...not too sure if i am doing the correct way
$DCITS_SQL << EOF
SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON VERIFY OFF TIMING OFF TERMOUT OFF
spool $tmpfile
select a.FIN,a.STAFF_NAME_X,b.FIN,b.DEPT_C from ci_5day_staff a, ci_cits_consol_dtls b where a.FIN=b.FIN;
spool off
exit
EOF
while read $tmpfile
do
if [ "$tmpfile" ]#check if line is not null
then
#if line not null, parse the line into words/variables
set $tmpfile #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo "$fin,$name,$gway" >> $final
fi
done
while read line
do
if [ "$line" ]#check if line is not null
then
#if line not null, parse the line into words/variables
set $line #set the line to positional variables, in this case is $1 and $2
fin ="$1" #staff fin number
name="$2" #name of staff
gway="$3"
echo "$fin,$name,$gway" >> $final
fi
done <$tmpfile