Sqlplus command is not working via plink - shell

I have a shell script in which I am using sqlplus command to fetch the data from database (Installed on Linux). same script is working fine on Linux environment. When I execute the script on window environment via using below batch file.
set ORACLE_TERM=xterm
set ORACLE_BASE=/home/pwcadm/app/pwcadm
set ORACLE_HOME=/home/pwcadm/app/pwcadm/product/11.2.0/client_1
set ORACLE_HOSTNAME=kyora02.kymab.local
set ORACLE_SID=orcl
set ORA_NLS11=$ORACLE_HOME/nls/data
set LANG=en_US.UTF-8
set PATH=/opt/CollabNet_Subversion/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/home/pwcadm/app/pwcadm/product/11.2.0/client_1/bin:/home/pwcadm/app/pwcadm/product/11.2.0/client_1/bin:/home/pwcadm/app/pwcadm/product/11.2.0/client_1/lib/site_perl/5.8.3/i686-linux-thread-multi:/home/pwcadm/app/pwcadm/product/11.2.0/client_1/perl/lib/5.10.0/x86_64-linux-thread-multi:/home/pwcadm/app/pwcadm/product/11.2.0/client_1/perl/bin:/home/pwcadm/Informatica/PowerCenter9.1.0.3/server/bin
set LD_LIBRARY_PATH=/home/pwcadm/app/pwcadm/product/11.2.0/client_1/lib:/home/pwcadm/app/pwcadm/product/11.2.0/client_1/lib32:/home/pwcadm/Informatica/PowerCenter9.1.0.3/server/bin
cd C:\Program Files\PuTTY
plink csaadm#172.16.122.11 -pw csaadm /app/csa/REG_AUTOMATION/scripts/CHECK_GAN_INSERT.sh
Batch file is prompting the below error message. Even I have set all the paths.
C:\Program Files\PuTTY>plink csaadm#172.16.122.11 -pw csaadm /app/csa/REG_AUTOMA
TION/scripts/CHECK_GAN_INSERT.sh
Error 6 initializing SQL*Plus
SP2-0667: Message file sp1<lang>.msb not found
SP2-0750: You may need to set ORACLE_HOME to your Oracle software directory
FAIL
/app/csa/REG_AUTOMATION/scripts/CHECK_GAN_INSERT.sh: line 27: [: -ne: unary oper
ator expected
CHECK_GAN_INSERT.sh
ACCOUNT_GLOBAL_COUNT=$(echo "
set heading off
set feedback off
set verify off
set trimspool on
set trimout off
set pagesize 0
set space 0
whenever sqlerror exit 2;
SELECT COUNT(*) FROM ACCOUNT_GLOBAL WHERE NAME='test';
"|/home/pwcadm/app/pwcadm/product/11.2.0/client_1/bin/sqlplus -S ${DB_USERNAME}/${DB_PASSWORD}#${CONNECTING_STRING})
EROR_MSG=$(echo ${ACCOUNT_GLOBAL_COUNT} |grep ORA|wc -l)
if [ ${EROR_MSG} -ne 0 ]
then
echo "${ACCOUNT_GLOBAL_COUNT}"
exit;
fi
if [ ${ACCOUNT_GLOBAL_COUNT} -ne 0 ]
then
echo "PASS"
else
echo "FAIL"
fi
Please help.

We haven't enough information about your problem, but here is my guess:
you have to set ORACLE_HOME env. var each time you log in (or add it in auto executable scripts),
you have to extend PATH too (use export PATH=$PATH:$ORACLE_HOME/bin),
also, may be you need to start Oracle instance.
Check these three points and update your question if your problem is still not solved.

Related

sqlplus: get parameters of file.sql execution

From a bat file I am using a process which is calling SQL/Plus in the same way:
#echo off
start sqlplus user/password#instance_name file.sql <instance_name>
echo End of process
pause
Inside file.sql I have something like :
SET FEEDBACK OFF
SET UNDERLINE OFF
SET PAGESIZE 0
SET VERIFY OFF
SET SCAN ON
SET HEADING OFF
SET RECSEP OFF
SET TRIMSPOOL ON
SET FEEDBACK OFF
SET TERMOUT OFF
SET LINESIZE 1000
SET BLOCKTERMINATOR OFF
set instance_name=<FROM PARAMETER>
SET VERIFY ON
SET HEADING ON
EXIT
How can I get the name which I am passing as parameter in SQL/Plus?
Use &1
From the documentation the SQL/Plus command has the syntax:
SQLPLUS [ [Options] [Logon|/NOLOG] [Start] ]
Then the START parameter:
Start
#{url|file_name[.ext]} [arg ...]
Specifies the name of a script and arguments to run. The script can be called from the local file system or from a web server.
SQLPlus passes the arguments to the script as if executing the file using the SQLPlus START command. If no file suffix (file extension) is specified, the suffix defined by the SET SUFFIX command is used. The default suffix is .sql.
See the START command for more information.
Then for the START command:
arg ...
Data items you wish to pass to parameters in the script. If you enter one or more arguments, SQL*Plus substitutes the values into the parameters (&1, &2, and so forth) in the script. The first argument replaces each occurrence of &1, the second replaces each occurrence of &2, and so on.

Passing parameter from window bat to UNIX shell script

i know topic seems very familiar and there are many answers given for same, but my issue is something else.I have a .bat file in which i am passing more then 10 parameters(I know limit is 9 but i need it).It seems to be working fine.Script is below-:
#ECHO OFF
setlocal EnableDelayedExpansion
set n=0
for %%a in (%*) do (
set vector[!n!]=%%a
set /A n+=1
)
SET sadminUser=%vector[0]%
SET sadminPassword=%vector[1]%
SET dsnProvider=%vector[2]%
SET dbUserName=%vector[3]%
SET schemaFilePath=%vector[4]%
SET ddldictschemalogPath=%vector[5]%
SET repositoryName=%vector[6]%
SET ddlimpschemalogPath=%vector[7]%
SET grantUserRole=%vector[8]%
SET userId=anyuser
SET host=myhost
SET password=password
SET datatable=%vector[9]%
SET indexTable=%vector[10]%
SET ddlimpschemalogPath2=%vector[11]%
echo %ddlimpschemalogPath2%
echo y | "C:\Program Files\PuTTY\plink" -ssh %userId%#%host% -pw %password% exit
"C:\Program Files\PuTTY\plink" -ssh %userId%#%host% -pw %password% "PATH=/bin:/usr/bin:/usr/local/bin /opt/siebel/w44gq8sw/DDL_Sync.sh %sadminUser% %sadminPassword% %dsnProvider% %dbUserName% %schemaFilePath% %ddldictschemalogPath% %repositoryName% %ddlimpschemalogPath% %grantUserRole% %datatable% %indexTable% %ddlimpschemalogPath2%" > ddlSuccess.txt 2>&1
Now as you see i am doing echo %ddlimpschemalogPath2% which is last parameter in array,and i can see correct output as well.
Problem is when i try to pass these parameters into UNIX Shell Script.You can see i am doing in bat file using putty command line Plink.I can successfully connect to shell script as well,And i am trying to echo all the passed parameters in shell script.But facing some issue . Script is below-:
#!/bin/bash
sadminUser=$1
sadminPassword=$2
dsnProvider=$3
dbUserName=$4
schemaFilePath=$5
ddldictschemalogPath=$6
repositoryName=$7
ddlimpschemalogPath=$8
grantUserRole=$9
datatable=${10}
indexTable=${11}
ddlimpschemalogPath2=${12}
echo "$sadmimUser"
echo "$sadminPassword"
echo "$ddlimpschemalogPath2"
echo password | sudo -S -l
sudo host << EOF
// Do something else
EOF
I Found one issue. In .bat i have parameter called -: repositoryName . When i do echo %repositoryName% it gives "Siebel Repository" correct output. Now when this spaced value is passed as parameter to shell script it breaks into 2 different values so:
These two parameter in script take 2 different values-:
repositoryName=$7
ddlimpschemalogPath=$8
Output-:
Siebel
repository
And it should be one value for parameter repositoryName=$7 . Giving value Siebel Repository. Why is this happening? Can this me issue why value are up and down?
As you can see in .bat i am making call to shell script, and passing parameters taken from .bat file as below-:
DDL_Sync.sh %sadminUser% %sadminPassword% %dsnProvider% %dbUserName% %schemaFilePath% %ddldictschemalogPath% %repositoryName% %ddlimpschemalogPath% %grantUserRole% %datatable% %indexTable% %ddlimpschemalogPath2%" > ddlSuccess.txt 2>&1
You can see complete line above in .bat.
Invoking .bat file -:
dlSync.bat "SAD" "glob81" "gepf_DSN" "SIEBEL" "/global/u70/globepfdev/siebel/schema.ddl" "/global/u70/globepfdev/siebel/siebsrvr/log/dev2prod/output/expschem.log" "Siebel Repository" "/global/u70/globepfdev/siebel/siebsrvr/log/dev2prod/output/ddlsync1.log" "SSE_ROLE" "GLOB_DATA_SMALL" "GLOB_INDEX_SMALL" "/global/u70/globepfdev/siebel/siebsrvr/log/dev2prod/output/ddlsync2.log"
Same parameter are passing out to shell script . where "Siebel Repository" breaks into 2. Thanks

Execute SQL Plus SQL command from batch-cmd window hangs

I am trying to execute a PL-SQL statemtn in a file and log the results to a log file. It works, but the DOS window hangs and I have to manually close it.
Am I ending the SqlPlus session incorrectly?
rem SET TERMOUT OFF;
SET SqlPlusExe=C:\Oracle\product\11203_32bit\CLIENT_1\bin\sqlplus.exe
SET MyUser=MyID
SET MyPassword=MyPwd
SET Host=RXODSDEV.CIGNA.COM
SET SqlFile=C:\Users\MyLanId\Desktop\SQLPlus\test.sql
SET LogFile=C:\Users\MyLanId\Desktop\SQLPlus\test.log
%SqlPlusExe% %MyUser%/%MyPassword%#%Host% #%SqlFile% >> %LogFile%
quit;
/
For Windows-scripting I recommend you to set the environment variable "LOCAL" ("TWO_TASK" on linux). The variable will specify you connection string.
set LOCAL=RXODSDEV.CIGNA.COM
REM Create the file to run
#(
echo connect %MyUser%/%MyPassword%
echo #%SqlFile%
echo exit^;
) > %TEMP%\run.sql
sqlplus /nolog #%TEMP%\run.sql >> out.log
But who is doing DOS scripting these days? Powershell is so much more fun!
Maybe you find my launcher script useful, take a look at http://www.unix.com/windows-and-dos-issues-and-discussions/256021-windowss-batch-launcher-oracle-sql-linux-sh-scripts-available-here.html

CRON and SQLPLUS

I want to run a script, which contains some sqlplus commands, in cron.
The problem is, that the sqlplus command won't be executed for some reason, when executed in cron. If I execute it by myself, the script runs fine.
I've checked some forums, even the topics here on stackoverflow.com and found some tips regarding the correct setting of environment variables. But even after double checking this, the script doesn't work.
Here is my script:
echo $ORACLE_HOME|grep "oracle" > /dev/null
if [ $? = 1 ] ; then
echo "Setting environment variable"
# Setting oracle environmet
. /usr/oracle/product/10.2.0/.profile
NLS_LANG='AMERICAN_GERMANY.WE8ISO8859P1'
fi
/usr/oracle/product/10.2.0/bin/sqlplus username/password #basics.sql > export.file
basics.sql contains:
set pagesize 0
set feedback off
set heading off
set linesize 400
set NULL nll
SELECT SOME_FIELDS FROM TABLE ORDER BY FIELD;
EXIT;
Any ideas?
shell environment is very important for Oracle and almost not there when using cron. As always there are several ways to solve this.
use full qualified paths - a bit inflexible
make the script to setup it's own execution environment
setup the execution environment in cron, when calling the script.
A pretty much standard way of setting up your environment from withing the script is by using the oraenv script, normally located in /usr/local/bin
ORACLE_SID={your_sid}
ORAENV_ASK=NO
type oraenv >/dev/null 2>&1 || PATH=/usr/local/bin:$PATH
. oraenv
SQLPATH=$HOME/sql
export SQLPATH
do your stuff
from the cron line:
10 10 * * * $HOME/.profile;$HOME/bin/your_script >$HOME/log/your_script.log 2>&1
This assumes that the .profile is not interactive and export the needed environment.

shell script error while running .sql file

While calling .sql file from shell script required data is retrieved but after completion - below errors are shown.
WHENEVER: not found.
SET: not found.
SET: not found.
SET: not found.
run command
sqlplus -s user/pasd#oracle_sid #file.sql
file.sql
WHENEVER SQLERROR EXIT 1
SET TERMOUT OFF
SET ECHO OFF
SET EMBEDDED ON
SET FEEDBACK OFF
SET HEADING OFF
spool file.log
select 'xyz' from dual;
spool off;
exit;

Resources