cannot execute sqlplus in shell script under cron


 
Thread Tools Search this Thread
Operating Systems Solaris cannot execute sqlplus in shell script under cron
# 1  
Old 06-10-2011
cannot execute sqlplus in shell script under cron

Hi,
I have a bourne shell script that needs to login into sqlplus and execute a stored procedure. I need this shell script to be run under a user crontab.
It works fine if run under normal shell prompt.
But it gave error message in my log file when run under crontab:

Code:
SQL*Plus: Release 10.1.0.5.0 - Production on Fri Jun 10 18:51:00 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name: SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon>  ::= <username>[/<password>][@<connect_identifier>] | /
Enter user-name: Enter password:
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
Execution Completed

This is the shell script:
Code:
PATH=$PATH; export PATH;
ORACLE_HOME=/orabin/10.1.2;
export ORACLE_HOME;
/orabin/10.1.2/bin/sqlplus    oper/MyPassword <<EOF
execute  MY_STORED_PGM_PKG.CREATE_PGM;
exit;
/
EOF
echo "Execution Completed "

I need to bring in the login env variables (like in .profile).
I am using SunOS 5.10 = Solaris 10.
Thanks.

Last edited by radoulov; 06-10-2011 at 09:35 AM.. Reason: Code tags!
# 2  
Old 06-10-2011
And how exactly are you passing the login information - oper/MyPassword - to the script?
# 3  
Old 06-12-2011
reply

It is hard coded.
# 4  
Old 06-13-2011
Please add -xv to the script and post the output of its execution via crontab.
# 5  
Old 06-13-2011
Please go through this:
https://www.unix.com/shell-programmin...cle-query.html

it may help you..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to execute 10 sql files from a folder through sqlplus in shell script?

I am new to shell scripting and i want to know how to execute the *.sql files from a folder through sqlplus in shell script and files should be execute in sequentially one by one while execution if any ORA error it has to exit from sqlplus session 1) scripts from external folder 2) logs has... (1 Reply)
Discussion started by: sreekanth Reddy
1 Replies

2. Shell Programming and Scripting

Need assistance to define path on a script which cron will execute

I have written a script to execute some sql statement via executable file. It is working fine via command line, however when I schedule it in cron. The executable file is looking for library file in its root directory. Wonder where does cron run the script from, and can we get the script... (4 Replies)
Discussion started by: jaapar
4 Replies

3. UNIX and Linux Applications

how to execute multiple .sql scripts from within a shell script using sqlplus

using sqlplus I want to execute a .sql script that has dbms_output statments in rhe script. I want to write the dbms_output statements from .sql file to a log file. is this possible. thanks any help would be appreciated :wall: (1 Reply)
Discussion started by: TRS80
1 Replies

4. Shell Programming and Scripting

Difference between using shell or cron to execute a script

Hi! Maybe i am here in the wrong section for the problem, but let me try to explain. I have the following simple backup script, as a solution till the final backup solution is online. Unfortunatly it will only work when executed manually. When i set up a cron job to execute the script, only the... (4 Replies)
Discussion started by: locutus01
4 Replies

5. Solaris

anomalous behaviour when I execute the script via cron

Hi , I am having a strange problem with my cron job : here is the script that I am scheduling from cron WrapperScript.ksh #!/bin/ksh ########## Global Variables ########## DATE=$(date +"%b-%d-%y") TIME=$(date +"%H:%M") LOGFILE=sonar_execution_$DATE.log ########## Main Processing... (2 Replies)
Discussion started by: alookachaloo
2 Replies

6. Shell Programming and Scripting

URGENT: cron job not running the sqlplus command in shell script

cron job not running the sqlplus command in shell script but the shell script works fine from command line.. Cronjob: 5 * * * * /home/dreg/script.sh script.sh: #!/bin/ksh /oracle/u000/app/oracle/product/10204/GEN/bin/sqlplus -s <user>/<pass>@<sid/home/dreg/sqlscript.sh ... (18 Replies)
Discussion started by: Ikea
18 Replies

7. Shell Programming and Scripting

cron does not execute script properly

I have a simple script that checks for certain printers and records them to a file. When I run the script manually at the command prompt, it works perfect, but when I run the script via cron, nothing happens. No errors reported, and no records are written out. I'm using Solaris 10. Below is the... (4 Replies)
Discussion started by: lmatlebyane
4 Replies

8. UNIX for Dummies Questions & Answers

a cron job needs a perl script to execute

Hello evreyone, this is my first post, and to say i'm new to this is an understatement. I know very little about perl scripts and hope some one can help me. i'm looking to get a script that a cron job can execute. what the script needs to to is 1) connect to a mysql database 2) go to a... (2 Replies)
Discussion started by: Exader
2 Replies

9. UNIX for Dummies Questions & Answers

Shell Script And SQLPLUS

i'm having real problems retrieving the returncode of my sqlplus-call. I found a lot of informations on the net, but havn't been able to get it running so far, so now i ask for some help ;) I do start the sqlplus out of my shell script with the parameters stored in the proc_clips.sql, which is... (6 Replies)
Discussion started by: maco_home
6 Replies

10. Shell Programming and Scripting

script execute by cron problem, but manual ok

Hi; I'm facing the problem with my script like below 30 0 * * * /data/SCRIPT/LOADLOGS/loadata1.sh 2 1 >> /tmp/loaddata.txt loadata1.sh calling a another 2 scripts which we need to exe in sequence. when it perform by cron jon, sometimes it just can process 20 recs or less or nothing but... (6 Replies)
Discussion started by: izai
6 Replies
Login or Register to Ask a Question