SQL PLUS Command 'ACCEPT' is not waiting for user input with sh shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SQL PLUS Command 'ACCEPT' is not waiting for user input with sh shell script
# 1  
Old 02-23-2010
MySQL SQL PLUS Command 'ACCEPT' is not waiting for user input with sh shell script

Dear All,

The sqlplus 'Accept' command is not waiting for user input when I include the command within a shell script.

Note: The 'Accept' command is working fine if I execute it in a SQLPLUS Prompt.

Please fins the below sample script which i tried.


SCRIPT:
--------
Code:
#! /bin/sh
 
sqlplus -s uname/pwd@samplDB << EOF
 
set heading off
set feedback off
 
ACCEPT X PROMPT 'ENTER X: '
 
select * from sam_tab where s_name like '%&X%';
 
exit
 
EOF
 



OUTPUT:
---------

The above script is not waiting for the user to key in the input.

But, when i tried the below SQL Codes in SQLPLUS Editor it works as expected.

----
ACCEPT X PROMPT 'ENTER X: '

select * from sam_tab where s_name like '%&X%';
------

Can anyone help me out of this??

Thank you all for your valuable time and Answers..
Smilie

Last edited by vbe; 02-23-2010 at 05:40 AM.. Reason: codetags please...
# 2  
Old 02-23-2010
Code:
#!/bin/ksh
echo "enter a value \c"
read value
printf "'%s'"  $value | read X
sqlplus -s uname/pwd@somedb << EOF
set heading off
set feedback off

 
select ${X} from dual;
 
exit
 
EOF

One way to do this.
# 3  
Old 02-23-2010
Or:
first script:

Code:
#! /bin/sh

sqlplus -s uname/pwd@samplDB << EOF

start mysqlscript
exit;
EOF

in mysqlscript.sql:
Code:
WHENEVER SQLERROR EXIT


set heading off
set feedback off

select * from sam_tab where s_name like '&X';
 
exit

# 4  
Old 02-24-2010
MySQL

Thank you for your responses.

But, I am looking for the script to do the below requirement

Code:
sqlplus -s uname/pwd@samplDB << EOF
 
set heading off
set feedback off
 
ACCEPT X PROMPT 'ENTER X: '
 
select * from sam_tab where s_name like '%&X%';
here I want to get the user input again to delete the paricular row.--

ACCEPT is_ok PROMPT 'Shall I delete the Row? [Y/N] : '

-- here i want execute the delete stamt if the user enters "Y" 
if [ &is_ok == "Y" ] Then
delete from sam_tab where s_name like '%x%';
end if;

exit
EOF


please advice me if this is possible. I tried with this ACCEPT Statement.
It is prompting the given comments (like Enter X: ) but, it is not waiting user to enter the inputs.

please advice.. how can i acheive this..

Last edited by radoulov; 03-04-2010 at 04:11 AM.. Reason: changed the color as adviced by pludi; radoulov: use code tags, please ...
# 5  
Old 03-04-2010
Still Not Working

Hi Vbe,

Thanks for the solution..

I have tried the script as of your solution.

But, still it is not waiting for the user to enter the input.
please verify my script below and please advice.

t1.sql is as follows:-
Code:
WHENEVER SQLERROR EXIT
 
set heading off
set feedback off
select * from sam_db where no=&inp;
exit

and t1.sh is as follows:-
Code:
#! /bin/sh
sqlplus -s uname1/pwd1@testDB << EOF
start t1.sql
exit;
EOF

when i execute the script, i got the respond like below:-
Code:
Enter value for shall_i_show_you: old 1: 
select * from sam_db where no=&inp
new 1: 
select * from sam_db where no=exit;

can you suggest anything for me..

Last edited by radoulov; 03-04-2010 at 04:14 AM.. Reason: Code tags, please!
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

Shell read command is not waiting for user input

Hi, i am working on one automation , for that i have writing one shell program that take user input in "while read line" block. but read command is taking value that is readed by While block. while read line; do command 1; command 2 echo -n "Do you want to continute > " read rsp... (2 Replies)
Discussion started by: ranvijaidba
2 Replies

3. Shell Programming and Scripting

Shell script to accept user input on the fly

I want a shell script that accepts user input simultaneously when performing other tasks. Example: A shell script should echo some messages on the console and when the user presses some keys it should respond to that action. say, when user presses the key A - more information should be printed... (2 Replies)
Discussion started by: Arun_Linux
2 Replies

4. Shell Programming and Scripting

How to write a shell script to automatically accept return key with out user intervention?

Hi Friends, i am creating a shell script which is accepting file name as input parameter from Java and invoking finacle service. The service will accpet text file,B2k_session id,etc and upload the text file data in finacle database. My shell script looks like this:- #! /bin/ksh... (2 Replies)
Discussion started by: vadlamudy
2 Replies

5. Programming

How to accept multiple lines input from User in C?

Hi I want to accept multiple lines input with spaces from User and i have a working code like this. char sRes; char sReq; printf("Please enter request:"); scanf("%",sReq); /* Accept the input from user */ printf("\nPlease enter response:"); scanf("%",sRes); but the... (4 Replies)
Discussion started by: AAKhan
4 Replies

6. Shell Programming and Scripting

User Input Shell Script

Hello I am trying to create a user input shell scipt. The objective is user should enter the circuit number and the input is saved in a log file. If the user does not enter anything then the question should prompt it until the circuit no. is entered. Can any one please correct the code below.... (3 Replies)
Discussion started by: sureshcisco
3 Replies

7. UNIX for Dummies Questions & Answers

accept user input?

how would i accept user input from the keyboard? (2 Replies)
Discussion started by: JamieMurry
2 Replies

8. Programming

Detecting if command is waiting for input

Hi, After doing a fork and executing a shell, we execute (third party) commands which are essentially non-interactive. But some of them ask for input, under some (unforeseeable) circumstances. When this happens we go on waiting for output. Their is timeout, of course, but we don't seem to know... (5 Replies)
Discussion started by: slash_blog
5 Replies

9. UNIX for Dummies Questions & Answers

Command to accept input

I am trying to write a one line command for Oracle grid control. I am using a semi-colon to separate the commands. But, I am having a problem with a shell script accepting input. Wondering if you can help. Here is what I am trying to do: (PGPRD5432)@prd01:/> cd /export/home/postgres ##... (3 Replies)
Discussion started by: rexmabry
3 Replies

10. Shell Programming and Scripting

Accept user input - only numbers

I have a situation where I want the user to enter only numbers in response to a READ command. I have some validation to restrict the number to be between 1 and 12, but if the user type in some characters the script echoes some error message and goes to the next command. Below is a snippet of the... (1 Reply)
Discussion started by: pvar
1 Replies
Login or Register to Ask a Question