shell - Syntax error at line 1 : `(' is not expected -
as i'm new unix, can why error?
error: 0403-057 syntax error @ line 1 : `(' not expected
unix server used: aix servname 1 6 00f635064c00
script used (to send email alert if day before yesterday source files didn't arrive):
#!/usr/bin/ksh count=$(sqlplus $prod_db @select count(*) file_audit (file_name '%abc%' or file_name '%dce%') , substr(file_name,17,8)=to_char(to_date(sysdate-2,'dd/mm/yy'), 'yyyymmdd') > asa_file_count.log) daybefore=`tz=aaa48 date +%d-%m-%y` if [[ $count -lt 20 ]] echo "alert - source files yet received date: $daybefore" | mail -s "alert : source data files missing" s@g.com fi
parentheses special shell. sql script contains parentheses don't want shell process. however, shell processes non-quoted parentheses. therefore, can use quotes prevent parentheses in sql being interpreted shell:
count=$(sqlplus $prod_db "@select count(*) file_audit (file_name '%abc%' or file_name '%dce%') , substr(file_name,17,8)=to_char(to_date(sysdate-2,'dd/mm/yy'), 'yyyymmdd')" > asa_file_count.log) # ^ , similarly, closing quote @ end, before ">asa_file..." .
now, there second issue: have
count=$(sqlplus ... > asa_file_count.log)
however, think means count
empty, since count go asa_file_count.log
, not available captured $()
. believe removing >asa_file_count.log
want:
count=$(sqlplus "$prod_db" "<your query>")
(i put double-quotes around $prod_db
in case prod_db
's value contains spaces.)
Comments
Post a Comment