I have script, which performing sql queries and put output into file.
When I run this script manually, its working fine, but when I want to schedule it with cron I am getting errors...
I defined LD_LYBRARY_PATH and ,but no result. After I defined it, I am getting error:
[root@dsafn1 20121016]# more NOKRWW_PS_INTERSHO_MNC1_RAW-201210160900.csv
ERROR:
ORA-12545: Connect failed because target host or object does not exist
SP2-0640: Not connected
I tried to define:
HOST = scv2db.r01.netact.azerfon.az
but got same error.
Here is part of script:
[root@dsafn1 ttg_project]# more run.sh
#!/bin/bash
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/10.2.0.2/client/lib:{/usr/lib/oracle/10.2.0.2/client/lib:{}:/opt/nokia/oss/lib:/opt/nokia/oss/tao/lib:/usr/lib:/usr/lib/or
acle/10.2.0.2/client/lib}:/opt/nokia/oss/lib:/opt/nokia/oss/tao/lib:/usr/lib:/usr/lib/oracle/10.2.0.2/client/lib
export LD_LIBRARY_PATH
PATH=$PATH:/usr/lib/oracle/10.2.0.2/client/bin:/opt/nokia/oss/bin:/opt/nokia/oss/perl/bin:/opt/nokia/oss/tao/bin:/bin:/usr/bin:/usr/lib/oracle/10.2.0.2/client/bin:/opt/nok
ia/oss/bin:/usr/lib/oracle/10.2.0.2/client/bin:/opt/nokia/oss/bin:/opt/nokia/oss/perl/bin:/opt/nokia/oss/tao/bin:/bin:/usr/bin:/usr/lib/oracle/10.2.0.2/client/bin:/opt/nok
ia/oss/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/sbin:/opt/nokia/oss/sbin:/root/bin:/usr/sbin:/opt/nokia/oss/sbin
export PATH
ORACLE_HOME=/usr/lib/oracle/10.2.0.2/client
export ORACLE_HOME
ORACLE_SID=oss
export ORACLE_SID
#
#---------- Creating folder in /root/ttg_project/output with current date --------------
#
cd /root/ttg_project/
mkdir ./output/20`date '+%y%m%d'`
chmod 777 ./output/20`date '+%y%m%d'`
#sleep 30
#
#---------- End of creating folder in /root/ttg_project/output with current date --------------
#
#
#---------- Running Queries with output to /root/project_ttg/output/Current_Date_Folder_Name -----------
#
/usr/lib/oracle/10.2.0.2/client/bin/sqlplus -s /nolog <<EOF > ./output/20`date '+%y%m%d'`/NOKRWW_PS_INTERSHO_MNC1_RAW-20`date --date="1 hour ago" '+%y%m%d%H'`00.csv
connect rdr/rdr
set linesize 10000
SET PAGESIZE 50000
SELECT
'RNC_ID'||'|'||
'WBTS_ID'||'|'||
..............................
..............................
Could you please let me know where the problem is?
Thanks in advance.
/root/ttg_project/run.sh - is the script which I am trying to run.
---------- Post updated at 05:08 PM ---------- Previous update was at 11:09 AM ----------
I added some parameters and now, when trying to connect i am getting this error:
[root@dsafn1 20121016]# more NOKRWW_PS_INTERSHO_MNC1_RAW-201210161600.csv
ERROR:
ORA-12545: Connect failed because target host or object does not exist
SP2-0640: Not connected
[root@dsafn1 20121016]#
You shouldn't have to add all the 'export' items to your shell script if you can run sqlplus from the command line.
You should be able to just put the following lines at the top of your shell script:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
Or run your cronjob like the following so that the script is aware of the user environment variables:
## minute, hour , day of the month, month of the year, day of the week script
## (0-59) (0-23) (1-31) (1-12) (0-6 0-Sunday)
##--------------------------------------------------------------------------------------------------
00 08 * * 2 . ~/.bashrc; /path/to/script/script.sh
And per the error(ORA-12545: Connect failed because target host or object does not exist) you are getting, check your tnsnames.ora file and look at this link: ORA-12545: Connect failed because target host ...