sqlplus output from ksh.


 
Thread Tools Search this Thread
Operating Systems Solaris sqlplus output from ksh.
# 1  
Old 12-17-2011
sqlplus output from ksh.

Hi All, I have the below simple script.
It runs just fine by itself when I manually invoke it.
But once I put it in the crontab with entry:

Code:
* * * * * /users/myuser/test.ksh >> /users/myuser/log/test.txt

"

It does NOT print the returned value ($REMAIN) from the DB!?

The result in the text file is just nothing like this:

Code:
start: Sat Dec 17 17:59:00 EST 2011
Returned value=

Anyone has any idea? It is obviously not a permission issue otherwise even those static texts would not have come back.....and when I run it manually it returnes the count. What else can it be? Thx.


Code:
#!/bin/ksh
 
echo "start:" $(date)
 
REMAIN=`sqlplus -silent uid/pwd@MYDB <<EOF
SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
 
select count(*) from my_table;
 
EXIT;
EOF`
 
echo Returned value=$(REMAIN)

P.S. Additionally, if I have multiple records coming back, or at least mutiple fields from the same record, how would that be handled in a simple way? But this is the next step, first I need to see why crontab does not get the return value to the text file output.

Last edited by zxmaus; 12-17-2011 at 09:13 PM..
# 2  
Old 12-17-2011
cron doesn't share your usual shell unless you explicitly define it, so your not necessarily getting to access oracle the way you're expecting. The output might be an empty resultset, but it's probably more like an error output. Be sure you're getting the proper environment from within cron.

You're also embedding backticks into a $() syntax...two additional forks off of your script's run. You might intend for defining your variable with double-quotes instead.
# 3  
Old 12-17-2011
Right, was kind of thinking along the same tracks. How do I make sure I get proper env from within cron? I am using crontab in my own user, which points to: /usr/bin/crontab
what "user" does crontab execute the script as?
And how do I further define oracle parm? Just set ORACLE_HOME within the sript you mean?

p.s. As for the $(REMAIN) I just use $REMAIN...

---------- Post updated at 10:23 PM ---------- Previous update was at 10:11 PM ----------

Hey, I set ORACLE_HOME and PATH and ORACLE_SID at the top of the script and it worked !! Thanks a lot dude....

p.s. Wouldn't there be an easier way? someone suggested putting "#!/bin/ksh" in the crontab file at the top ..but that did nothing!

---------- Post updated at 10:24 PM ---------- Previous update was at 10:23 PM ----------

Now where is a sample script to get mutiple values from the DB insead of just 1 variable?
# 4  
Old 12-18-2011
Quote:
Originally Posted by steve701
[...]

Hey, I set ORACLE_HOME and PATH and ORACLE_SID at the top of the script and it worked !! Thanks a lot dude....

p.s. Wouldn't there be an easier way? someone suggested putting "#!/bin/ksh" in the crontab file at the top ..but that did nothing!
The shell has nothing to do with the incomplete environment in this case.
You may define all your variables in a separate file and source it from all the scripts that need those variables.

Quote:
Now where is a sample script to get mutiple values from the DB insead of just 1 variable?
Please post a sample of the result set and an example of the expected result/output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Line break in sqlplus output through ksh script

Hi, I am new to shell script programming. I have written a ksh script to run the sql File placed in server directory and spool the output in destination directory. Below Command: $ORACLE_HOME/bin/sqlplus -s $ora_uid @$sqlfile_loc$testquery.sql > $opfiledirectory It is generating the output... (6 Replies)
Discussion started by: Sumit Arora
6 Replies

3. Shell Programming and Scripting

Shell Script (ksh) - SQLPlus query filter using a string variable

Using ksh, I am using SQLPlus to execute a query with a filter using a string variable. REPO_DB=DEV1 FOLDER_NM='U_nmalencia' FOLDER_CHECK=$(sqlplus -s /nolog <<EOF CONNECT user/pswd_select@${REPO_DB} set echo off heading off feedback off select subj_name from subject where... (5 Replies)
Discussion started by: nkm0brm
5 Replies

4. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

5. Shell Programming and Scripting

output arguments from a sqlplus

Hi. I need to output a 4 queries result into another application using result=`sqlplus -s ${3}/${4}@${2} << EOF ... query1 query2 query3 query4 .... echo "$metrics1" and returning those individual values into another app. (query1 and 3compute one value, query 2 and 4 compute 4... (3 Replies)
Discussion started by: shell_zen
3 Replies

6. UNIX for Dummies Questions & Answers

Getting output parameter in sqlplus

I need to get the output parameter from a stored procedure in sql plus using shell script. Can anyone help me please ... (1 Reply)
Discussion started by: risshanth
1 Replies

7. Shell Programming and Scripting

KSH Sqlplus problem

Hi, trying this =============================== Temp=`sqlplus -s user/passwd <<EOF WHENEVER SQLERROR EXIT 1 set serverout on set feedback off set heading off select nam from tabel1 where x=y; EOF` echo Temp>>$logfile ================================= The select statement is... (2 Replies)
Discussion started by: amitkr
2 Replies

8. Shell Programming and Scripting

How to acheive ALT+Enter of xls in Unix ksh/sqlplus

Hi, I am using sqlplus (called inside my ksh) to create a file which is mailed to the users as an xls. There is one DESCRIPTION column which is currently coming as wrapped, but, the users want a new line for each of the fields present in the desricription column. Below is an example - ... (11 Replies)
Discussion started by: Sree_2503
11 Replies

9. Shell Programming and Scripting

How to pass variable to SQLPLUS in a ksh script?

Hi, I am writing a ksh script which will use sqlplus to run a sql and pass 2 variables as the SQL request. In the ksh script, I have 2 variables which are $min_snap and $max_snap holding 2 different numbers. Inside the same script, I am using SQLPLUS to run an Oracle SQL script,... (6 Replies)
Discussion started by: rwunwla
6 Replies

10. Shell Programming and Scripting

Need help with ksh script that uses sqlplus, called from PHP

I have a ksh script that connects to sqlplus and dumps the query results into a file. The script works file when I run it from the command line, however, when I call it from PHP using system(), exec(), or shell_exec() commands, the script doesn't seem to run the query. It will create the text file... (7 Replies)
Discussion started by: j2owilson
7 Replies
Login or Register to Ask a Question