Пример 1
#!/bin/sh
username=\"Scott\"
password=\"@T!ger\"
host=10.x.xx.xxx
port=1521
service=esmd
ezconnect=$host:$port/$service
echo username: $username
echo password: $password
echo host: $host
echo port: $port
echo service: $servive
echo ezconnect $ezconnect
echo -e 'show user \n select 1 from dual; \n select sysdate from dual; \nexit;' | sqlplus -s $username/$password@$ezconnect
Выход:
oracle@esmd:~> ./test_echo.sh
username: "Scott"
password: "@T!ger"
host: 10.x.xx.xxx
port: 1521
service:
ezconnect 10.x.xx.xxx:1521/esmd
USER is "Scott"
1
----------
1
SYSDATE
---------
19-FEB-20
oracle@esmd:~>
Пример 2
#!/bin/sh
username=\"Scott\"
password=\"@T!ger\"
echo username: $username
echo password: $password
testoutput=$(sqlplus -s $username/$password << EOF
set pagesize 0 feedback off verify off heading off echo off;
show user
SELECT to_char(sysdate,'DD-MM-YYYY HH24:MI')||' Test passed' from dual;
@ulcase1.sql
exit;
EOF
)
echo $testoutput
Выход:
oracle@esmd:~> ./test_Upper_case.sh
username: "Scott"
password: "@T!ger"
USER is "Scott" 19-02-2020 15:08 Test passed
oracle@esmd:~>
Пример 3 теста . sh
#!/bin/bash
sudo -H -E -u oracle -s "/opt/oracle/test_Upper_case.sh"
Выход
esmd:~ # ./test.sh
username: "Scott"
password: "@T!ger"
USER is "Scott" 19-02-2020 15:50 Test passed
/ opt / oracle / test_Upper_case. sh
!/bin/sh
username=\"Scott\"
password=\"@T!ger\"
echo username: $username
echo password: $password
testoutput=$($ORACLE_HOME/bin/sqlplus -s $username/$password << EOF
set pagesize 0 feedback off verify off heading off echo off;
show user
SELECT to_char(sysdate,'DD-MM-YYYY HH24:MI')||' Test passed' from dual;
@/opt/oracle/ulcase1.sql
exit;
EOF
)
echo $testoutput