I am running an SQL script from bash. One of the scripts seems to be running fine, but the other script fails. Can you please advise what might be the cause for the 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 to open file "MyScript2.sql"
In Unix the access level for both is:
-rwxrwxrwx MyScript1.sql
-rwxrwxrwx MyScript2.sql
The error does give an indication that it is not able to access the file MyScript2.sql. But what I am curious about is how come it can access MyScript1.sql which is present in the same folder, but not MyScript2.sql?
Also if I run the file just in unix (using SQL*Plus) from the folder where the files are present it works fine. But if I run the same from a different folder it doesn't. Below example will explain it better
/Folder/having/the/files
both MyScript1.sql and MyScript2.sql run fine
/Some/random/folder
MyScript1.sql runs fine , but MyScript2.sql errors out
MyScript1actually get executed? What happens if you comment out the@MyScript1line?MyScript1does get execute . if I comment out@MyScript1, I only get the errorSP2-0310: unable to open file "MyScript2.sql"MyScript2.sqlvsMyscript2.sql. Have you tried renamingMyScript2.sqlsomehow differently?$SQLPATHset, and if so do you have a file calledMyScript1.sql, or a link to your real file with that name, in that directory? If you aren't running the script in the same directory as your files then you will need to give the full path (or set$SQLPATHin your acript, which might have side effcts (skippinglogin.sql, so just using the full path ought to work better).