oracle - SQL script not executing in bash -
i running sql script bash. 1 of scripts seems running fine, other script fails. can please advise might cause same?
#!/bin/bash sqlplus -s user/password@database << eof whenever sqlerror exit sql.sqlcode; set echo off set heading off @myscript1 @myscript2 exit; eof error: sp2-0310: unable open file "myscript2.sql"
in unix access level both is:
-rwxrwxrwx myscript1.sql -rwxrwxrwx myscript2.sql the error give indication not able access file myscript2.sql. curious how come can access myscript1.sql present in same folder, not myscript2.sql?
also if run file in unix (using sql*plus) folder files present works fine. if run same different folder doesn't. below example explain better
/folder/having/the/files
both myscript1.sql , myscript2.sql run fine
/some/random/folder
myscript1.sql runs fine , myscript2.sql errors out
you said:
if run file in unix (using sql*plus) folder files present works fine. if run same different folder doesn't.
if run bash script different folder have sql files, how expect sql*plus know find those? question becomes not 'why can't see myscript2.sql, why can see myscript1.sql. obvious answer can't, or @ least can't see version of file think it's seeing.
from sql*plus documentation:
sql*plus searches sql scripts, including login.sql, in current directory , in directories specified sqlpath, , in subdirectories of sqlpath directories.
so if haven't given full path sql file, search in current working directory - sitting when execute bash script, not directory bash script in, i.e. pwd shows - , in $sqlpath if set.
that suggests have copy of myscript1.sql in 1 of places, or possibly soft link real file. if had guess, i'd speculate wrote myscript.sql same directory script, copied directory before writing myscript2.sql. in case, myscript1.sql you're running might out of date, or become in future.
the short answer give full path sql files, either part of @ command, or changing directory in bash script before launching sql*plus.
Comments
Post a Comment