×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

If file Empty, then die giving error

If file Empty, then die giving error

If file Empty, then die giving error

(OP)
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 --> script

#!/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 

RE: If file Empty, then die giving error

Hi

The [ is a command. In modern shells there is a builtin function with that name, but there is also an old fashion standalone /usr/bin/[ executable too. So the space after [ is mandatory, like between any command and its parameter. BTW, the closing ] must be a separate parameter, so also delimited by a space :

CODE

   ,-- command
   |
if [ ! -f "$rowcount.txt" ]; then
     | \| \_____________/ |
     |  |        |        `-- parameter
     |  |        `----------- parameter
     |  `-------------------- parameter
     `----------------------- parameter 

Feherke.
feherke.github.io

RE: If file Empty, then die giving error

(OP)
Thanks,
I have ssolved this by using :

if [ `ls -l rowcount.txt | awk '{print $5}'` -eq 0 ]

RE: If file Empty, then die giving error

(OP)
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.

RE: If file Empty, then die giving error

(OP)
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..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close