Operating System - HP-UX
1827791 Members
2518 Online
109969 Solutions
New Discussion

Re: Input to command automatically

 
Soul_1
Respected Contributor

Input to command automatically

Hi all,

i want to give input to a command automatically.

for Example:
Normally i have to run the command say "x" for intiating sql query and afterwards ihave to give the sql commands and press enter

#x
SQL>select * from data_detail;
quit;
#

i need to auomate this .Please help me

Cheers !!
6 REPLIES 6
Horia Chirculescu
Honored Contributor

Re: Input to command automatically

Hello,

If you use sqlplus (x=sqlplus), you could make a sql script (your select/insert/whatever/quit will go there) and then se something like this:

sqlplus -s '/ as sysdba' @yourscript.sql


If you script would use some variable, you can add that variable at the end of this command like this:

sqlplus -s '/ as sysdba' @yourscript.sql $variable1

In your script.sql you can access that variable by $1.

Horia.
Best regards from Romania,
Horia.
Horia Chirculescu
Honored Contributor

Re: Input to command automatically

> by $1.

Sorry, it is &1. Read manual for sqlplus.

Horia.
Best regards from Romania,
Horia.
James R. Ferguson
Acclaimed Contributor

Re: Input to command automatically

Hi:

You could use a here-document:

sqlplus <
rariasn
Honored Contributor

Re: Input to command automatically

Hi,

# cat sample.sh

echo "..."
sqlplus / sample.sql
ERR=$(grep 'ORA-' sample.log)

if [ "$ERR" = "" ]
then
echo "SAMPLE: OK."
else
echo "sample: ERROR"
exit 3
fi


# cat sample.sql

spool sample.log
select * from data_detail;
spool off
exit;

Rgs,



Arturo Galbiati
Esteemed Contributor

Re: Input to command automatically

Hello,
don't use sqlplus user/password but:
sqlplus
conn user/password
....
exit

reason why is that by 'ps -ef|grep [s]lplus' in the first way it's possible to cach database password!!

HTH,
Art
Arturo Galbiati
Esteemed Contributor

Re: Input to command automatically

Hello,
don't use sqlplus user/password but:
sqlplus
conn user/password
....
exit

reason why is that by 'ps -ef|grep [s]qlplus' in the first way it is possible to cach database password!!

HTH,
Art