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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If file Empty, then die giving error

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hello Once Again,
I am putting finishing touches to my script.
Basically, it is functioning now, however, I wanted to additionally an if statement saying if there is no tables to be processed, the script should die, and exit with email saying there is no table to be repaired.
The if statement starts at Line #23.
However it is reporting error:

./spx_repair_sfgi_3.sh[23]: [!: not found

Code:
#!/bin/ksh

 dbname=sfgi
 export ORACLE_SID=$dbname
 export ORACLE_HOME=/orahome/app/oracle/product/10.2.05/dbq413
. /usr/sislocal/$dbname/to$dbname

#log into database
sqlplus -s splex/password << EOF


 set pagesize 0
 set linesize 4000
 set feedback off
 set trimspool on

 spool rowcount.txt;

select source_name from splex.count_match_vw;
 spool off;
EOF
#Begin if file empty, die and exit.
if [! -f "$rowcount.txt"]; then
mailx -s "Comparing the tables in Shareplex SFGI<->CTXI Environment produces no mismatch."  myemail@email.com<< END
END
else
mailx -s "The following tables have rowcount mismatch in Shareplex SFGI<->CTXI Environments"  myemail@email.com<< END
`cat rowcount.txt`
END
     # Create the file extensions and files to be used:
     basename=spsfgi
     now=`date '+%y-%m-%d_%H-%M-%S'`
     repair_dir=/orahome/app/oracle/home
     repairfile=$repair_dir/$basename.$now.sh
     logfile=$repair_dir/$basename.$now.log
     resultfile=$repair_dir/$basename.$now.out

     #remove  from table names.
     #`sed 's/"//g'rowcount.txt>tblname.tx`

     #loop through tblname.txt
     for tblname in `cat /orahome/app/oracle/home/rowcount.txt`
    do
     #set shareplex environment
     cd $repair_dir
     LOG_FILE=$repair_dir/rc_loop_rep_our.log
     . ./spenv_splex_Port#_sfgi.sh
     #export SP_SYS_PRODDIR=/orahome/app/SharePlex/10g/prod
     #export SP_SYS_VARDIR=/orahome/app/SharePlex/10g/varsplex_Port#_sfgi
     #export SP_COP_UPORT=splex_Port#
     #export SP_COP_TPORT=splex_Port#
     #export SP_SYS_HOST_NAME=seq
     export IW_HOME=$SP_SYS_PRODDIR/util


#log into Shareplex Console
#`cd $SP_SYS_PRODDIR/bin`
/orahome/app/SharePlex/10g/prod/bin/./sp_ctrl << EOSP > $LOG_FILE
list config
repair $tblname
exit
EOSP
mailx -s "Table following table is now repairing in Shareplex SFGI<->CTXI Environment"  myemail@email.com<< END
$tblname
`cat $LOG_FILE`
END

    done
rm rowcount.txt
fi
 
Hi

The [tt][[/tt] is a command. In modern shells there is a builtin function with that name, but there is also an old fashion standalone [tt]/usr/bin/[[/tt] executable too. So the space after [tt][[/tt] is mandatory, like between any command and its parameter. BTW, the closing [tt]][/tt] must be a separate parameter, so also delimited by a space :
Code:
[b][/b]   [gray],-- command[/gray]
   [gray]|[/gray]
if [highlight][[/highlight] [highlight pink]![/highlight] [highlight pink]-f[/highlight] [highlight pink]"$rowcount.txt"[/highlight] [highlight pink]][/highlight]; then
     [gray]| \| \_____________/ |[/gray]
     [gray]|  |        |        `-- parameter[/gray]
     [gray]|  |        `----------- parameter[/gray]
     [gray]|  `-------------------- parameter[/gray]
     [gray]`----------------------- parameter[/gray]

Feherke.
feherke.github.io
 
Thanks,
I have ssolved this by using :

if [ `ls -l rowcount.txt | awk '{print $5}'` -eq 0 ]
 
Hello All,
Additional help is required.
Though my if conditional cluse is catching empty tables, it does not catch error files.

Therefore my if routine is behaving as if there are table names in the output file.
Question - how can I catch situation where the file is empty or contain error logs such as:
ERROR at line 1:
ORA-19202: Error occurred in XML processing
ORA-00942: table or view does not exist
ORA-02063: preceding line from dbanme
ORA-06512: at "SYS.DBMS_XMLGEN", line 288
ORA-06512: at line 1

if [ `ls -l rowcount.txt | awk '{print $5}'` -eq 0 ] or [ `ls -l rowcount.txt | grep ERROR| greo ORA'` -ne 0]
then
mail error statement
else
process each recod.
done
fi

The above errors out.
 
Hello,
I am now using:
if [ `ls -l rowcount_sfgp_ctxp.txt | awk '{print $5}'` -eq 0 ] or [`ls -l rowcount_sfgp_ctxp.txt | grep {'ORA-'} -ne 0`]

but us giving error:
grep: can't open -ne
grep: can't open 0

Any advice..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top