我正在尝试编写一个脚本,我可以在其中以 dba 用户身份连接到 db 并计算用户数。最终我想更新我的脚本来检查用户是否存在;杀死他们的会话;然后删除用户。但目前我想从计算用户开始,只是为了确保我的脚本正在运行。
但看起来它没有连接到数据库。
echo
echo "3> Resetting databases..."
read -p "Enter Database Server Hostname: " db_host
read -p "Enter Database SID: " db_sid
read -p "Enter DBA User: " dba_usr
read -p "Enter DBA password: " dba_pwd
read -p "Enter Schema1 owner: " usr1
read -p "Enter alternate user1 " usr2
read -p "Enter alternate user2 " usr3
sqlplus -s $dba_usr/$dba_pwd@$db_sid << EOF
set timing off
set feedback off
set serveroutput off
DECLARE
usr1 varchar2(10) := '$usr1';
usr2 varchar2(10) := '$usr2';
usr3 varchar2(10) := '$usr3';
total INTEGER;
TYPE user_arr IS VARRAY(3) OF VARCHAR2(20);
users user_arr;
BEGIN
dbms_output.put_line('Entered inside this block...');
users := user_arr( upper(usr1),
upper(usr2),
upper(usr3) );
total := users.count;
FOR i in 1 .. total LOOP
dbms_output.put_line('Usernames are: '|| users(i));
END LOOP;
END;
/
EOF
输出如下所示:
3> Resetting databases...
Enter Database Server Hostname: HOSTNAME
Enter Database SID: SID
Enter DBA User: DBA
Enter DBA password: pwd
Enter Schema1 owner: user1
Enter alternate user1 user2
Enter alternate user2 user3
获取输入值后,它不做任何事情。我不知道出了什么问题。试图修复它但不能。谁能找出问题所在?谢谢!