How to call nested script in sqlplus - oracle

I have following script hierarchy.
Scripts/master.sql
Scripts/GB/gb.sql
Scripts/GB/user1/insert.sql
master.sql contains simple #script to call gb.sql
e.g.
#GB/gb.sql
gb.sql contains below
#user1/insert.sql
The problem is that if i run master.sql from Scripts directory, i get below error:
unable to find insert.sql
Whereas if I execute gb.sql from GB directory, ir run successfully.
Can you please help me?

SQL*Plus directories are always reletive to the original working directory. Your scripts will need to repeat the full path from the working directory each time.
Change gb.sql to:
#GB/user1/insert.sql
The ## can be used to reference files in the same directory as the running file, but ## does not work with sub directories.

Related

Airflow Bash Operator : Not able to see the output

I am a newbie to Airflow and trying to create a simple task of executing a bash file(whose job is just to create a directory). I have given the full path of the bash file to be executed (with a space at the end) in bash_command. However, upon triggering the DAG from the UI, I see no errors in the log as well as no folder created with the name specified in the bash file.
Can someone please help me fix the issue?
When BashOperator executes, Airflow will create a temporary directory as the working directory and executes the bash command. When the execution finishes, the temporary directory will be deleted.
To keep the directory created from the bash command, you can either
specify an absolute path outside of the working directory, or
change your working directory to a place outside of the temporary directory.
I am creating a test directory in the Airflow home directory.
p = BashOperator(
task_id='create_dir',
bash_command='pwd; mkdir $AIRFLOW_HOME/test; ls -al',
)

Executing a bash script from anywhere on Windows

I am on Windows.
I have a script file named basics.sh and here is what it contains:
cd opt-out-exam/abduvosid_malikov/IT
mkdir made_by_my_script
cd made_by_my_script
echo "Hello World" > hello.txt
so basically, basics.sh script file is responsible to:
go to folder opt-out-exam/abduvosid_malikov/IT
make a directory made_by_my_script
create hello.txt file with content Hello World
Right now. to execute this basics.sh script, I am going to IT folder and writing this command in the terminal:
./basics.sh
In order to execute this basics.sh script, is it compulsory for me to go to IT folder
OR
is it possible to execute this script file even if I am staying in another folder (lets say currently working directory is opt-out-exam)
The first line is a change directory command followed by a relative path, not absolute. In such cases, it is important where you run the script. (An absolute path would start with the filesystem root, i. e. /.)
If you run this script from a directory (I wouldn't call it a folder in this context) where the relative path opt-out-exam/abduvosid_malikov/IT does not exist, it won't cd into it. But it will make a new directory without any problem, it will also create the file and write a line into it.
So only the first line will fail if it's run somewhere else.
UPD: As Gordon Davisson pointed out, this means that you want to check whether the directory change actually took place or not.

Knife command works from one particular directory but not from others. why?

I have created an organization called "kaushikinc" on chef server and have a directory structure "C:/x/y/z/kaushikinc".
When I execute a command from kaushikinc folder, they work fine but when I execute from a parent or child folder, they dont work. What am I doing wrong?
Ex: from a child folder: No success or error message:
But a success when I try from kaushikinc folder
Edit: Adding a new image to show that the problem exists even when I pass the location of knife.rb config file
Edit2: I run across this problem only when I use "--all" option on "knife data bag from file" command. I am able to execute any other command from any directory with -c enabled.
Usually, this is because the directory you're in, or a parent directory, contains a .chef directory. knife searches for .chef in:
./.chef (current directory contains .chef)
~/.chef (homedir contains .chef)
parent directories (e.g. ./.. then ./../.. all the way back to /)
You can see some of the logic itself here.

Using Script to Execute C File in Different Directory

I am new to C, so apologies if this is a naive question. I have been given a script to execute C programs. The first line has the format:
./directory_name program_name program_parameter_1 program_parameter_2
When I execute the script from a different directory I get the following error:
No such file or directory.
When I execute the script from the named directory, I get a different type of error:
directory_name is a directory.
Does someone know what the script file is trying to accomplish?
I have read about commands that change directories through script files, but they don't seem to have this format (i.e. directory name following ./), so I am confused.
Thanks!
If the script is presenting a different behavior depending on the directory you are running it, that means the code inside the file is referencing some dependency that is mapped from a specific location.
Why don't you check the source and learn more about what the script is doing?
Are you confused about "./"? That's how you execute a script, you don't have to worry about what kind of interpreter will process this code, that's defined in the shebang (#!).
You can read more about it here:
http://en.wikibooks.org/wiki/C_Shell_Scripting/Hello

SQL script not executing in bash

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
You said:
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.
If you run the bash script from a different folder to where you have the SQL files, how do you expect SQL*Plus to know where to find those? The question becomes not 'why can't it see MyScript2.sql, but why it can see MyScript1.sql. The obvious answer is that it can't, or at least can't see the version of the file you think it's seeing.
From the SQL*Plus documentation:
SQL*Plus searches for SQL scripts, including login.sql, in the current
directory and then in the directories specified by SQLPATH, and in the
subdirectories of SQLPATH directories.
So if you haven't given the full path to the SQL file, it will search in the current working directory - where you are sitting when you execute the bash script, not the directory the bash script is in, i.e. what pwd shows - and the in $SQLPATH if it is set.
That suggests you have a copy of MyScript1.sql in one of those places, or possibly a soft link to your real file. If I had to guess, I'd speculate that you originally wrote MyScript.sql the same directory as the script, then copied it to another directory before writing MyScript2.sql. In any case, the MyScript1.sql you're running might be out of date, or is likely to become so in the future.
The short answer is to give the full path to the SQL files, either as part of the # command, or by changing to that directory in the bash script before launching SQL*Plus.

Resources