Computing.Net > Forums > Unix > Pass parameter from plsql to unix

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Pass parameter from plsql to unix

Reply to Message Icon

Name: abolk
Date: September 29, 2004 at 11:53:56 Pacific
OS: win 2K
CPU/Ram: Gig
Comment:

This is my first time ever writing a unix shell script, so I have no idea. Here is what we have going on. We have a view in oracle that I am selecting the count from. I want to pass the count into a variable and pass it into the unix shell script. If the count is not 0 then I want the shell script to sleep for 10 minutes and then query the view again. If somebody could please provide me with some code or any kind of help I would appreciate it.

Thanks!!!!



Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: September 29, 2004 at 12:45:09 Pacific
Reply:

Even if you ultimately need to execute a plsql block after determining that the view has rows, your 10-minute monitoring of the view could use sqlplus instead of plsql.

Will that approach be OK?


0

Response Number 2
Name: abolk
Date: September 29, 2004 at 13:38:32 Pacific
Reply:

Yeah that is my mistake. I meant to say sqlplus. You are correct. I just want to create a unix shell script the queries a view and if the view has rows then wait 10 minutes before I query it again.

Thanks


0

Response Number 3
Name: Jim Boothe
Date: September 29, 2004 at 14:33:28 Pacific
Reply:

The script below will check the view every 600 seconds, and when there is a row
count, it will <do whatever> such as run a plsql script, then break out of the while-loop and terminate.

#!/bin/sh
count=0
while true
do
echo "\
set pagesize 0
select count(*) from my_view;" |
sqlplus -s scott/tiger | read count
if [ $count -gt 0 ] ; then
   echo "Count detected: $count"
#  <do whatever>
   break # (out of the while-loop)
else
   sleep 600
fi
done
exit 0

Alternatively, if you want to keep monitoring every 10 minutes, then replace the above if-else with this:

if [ $count -gt 0 ] ; then
   echo "Count detected: $count"
#  <do whatever>
fi
sleep 600


0

Response Number 4
Name: abolk
Date: September 30, 2004 at 06:40:43 Pacific
Reply:

Here is the code I have

#!/bin/sh
count=0
while true
do
echo "\
set pagesize 0
select count(*) from bus_adm.dw_unfinished_reports;" |
sqlplus -s scott/tiger | read count
if [$count -gt 0]; then
echo "count is zero"
else
echo "count is not zero"
fi
done
exit 0

The error I'm getting is unfinished_reports.ksh[9]: [ERROR:: not found.

Also in the loop, what is the condition that is being evaluated. While what is true?

Thanks


0

Response Number 5
Name: abolk
Date: September 30, 2004 at 06:47:50 Pacific
Reply:

Also, if I have it echo "$count"

It echos ERROR. Appears that something is not working correctly with the variable.


0

Related Posts

See More



Response Number 6
Name: Jim Boothe
Date: September 30, 2004 at 07:45:52 Pacific
Reply:

In the statement:

if [$count -gt 0]; then

you need a space after the left bracket and a space before the right bracket.

Also, the while-loop does not have a sleep in it, so if it were working, it would be repeatedly running sqlplus over and over with no pause.

"while true" starts a while loop (delimited with do/done) that would run forever unless you break out of it because the expression "true" always evaluates as true.

As opposed to some other condition which might evaluate as either true or false such as:

while [ $count -eq 0 ]


0

Response Number 7
Name: abolk
Date: September 30, 2004 at 11:28:05 Pacific
Reply:

Jim, thanks for all of your help.

One more question. Is it possible to select multiple values from a query into variables? Select col1, col2 from table where date = sysdate....as an example. Could we then put col1 and col2 into variables?

Thanks again.


0

Response Number 8
Name: Jim Boothe
Date: September 30, 2004 at 12:52:48 Pacific
Reply:

Sure. Same solution, except change two lines to get the values into $a and $b:

select sum(a), sum(b) from my_reports;" |
sqlplus -s scott/tiger | read a b


0

Response Number 9
Name: abolk
Date: September 30, 2004 at 13:32:22 Pacific
Reply:

Well it kind of works. I think it might be the data I'm pulling. Here is my code.

echo "\
set pagesize 0
select to_char(sysdate,'yyyy-mm-dd hh24:mi'), to_char(trunc(sysdate) + .375, 'yyyy-mm-dd hh24:mi') from dual;" |
sqlplus -s $DB_LOGIN | read now nineam

And it splits it into 2 variables, but the time from variable now ends up in nineam.


Example:

For sysdate it pulls 9/30/2004 15:31
For sysdate + .375 it pulls 9/30/2004 9:00

The variables end up like this

now 9/30/2004
nineam 15:31 9/30/2004 9:00

Is it bringing the time from now down to nineam because there is a space?


0

Response Number 10
Name: abolk
Date: September 30, 2004 at 13:56:08 Pacific
Reply:

The other condition I'm trying to create is time. If there are 0 records in the table or it is after 9:00 then exit 0. Otherwise keep looping.

That is why I am selecting the times from dual


0

Response Number 11
Name: Jim Boothe
Date: October 1, 2004 at 06:24:39 Pacific
Reply:

Just return the row count from sqlplus. Then the while-loop can break out of the loop when the count is zero or when it determines that it is after 09:00 with:

if [ $(date +%H%M) -gt 900 ] ; then
break
fi

Or use -ge for greater-than-or-equal-to.


0

Response Number 12
Name: Jim Boothe
Date: October 1, 2004 at 06:32:09 Pacific
Reply:

And I intended to answer your question ...

Yes, you were outputting 4 space-delimited words from sqlplus. The read command will read one word into each variable, but if it runs short of receiving variables, it throws all of the remaining words into the last variable.

When I wnat to receive two words only, I use:

read word1 word2 garbage

That way, any words beyond two will be thrown into garbage instead of messing up my word2. And as an edit, I could check if I received any $garbage.


0

Response Number 13
Name: Jim Boothe
Date: October 1, 2004 at 06:54:06 Pacific
Reply:

If the time that you wanted to check from the database happens to be in a different time zone, you will of course need to make an adjustment for that if you use the date command instead.


0

Sponsored Link
Ads by Google
Reply to Message Icon

how do you get pthread to... ask for users age as inpu...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Pass parameter from plsql to unix

passing value from oracle to unix www.computing.net/answers/unix/passing-value-from-oracle-to-unix/7327.html

ftp from Win2000 to Unix www.computing.net/answers/unix/ftp-from-win2000-to-unix/4755.html

Pass parameters from a file www.computing.net/answers/unix/pass-parameters-from-a-file/5164.html