#!/usr/bin/ksh
i=0
echo "
set feedback off
set heading off
set pagesize 0
select username
from dba_users
where account_status = 'LOCKED';
exit
" | sqlplus -s scott/tiger@testdb | \
while read line
do
arr[$i]="$line"
i=$i+1
done
echo "locked user list is given below : "
i=0
echo "Total no. of users locked ${#arr[*]} "
while [ $i -lt ${#arr[*]} ]
do
print ${arr[$i]}
(( i=i+1 ))
done
echo "After Array Print"
i=0
while [ $i -lt ${#arr[*]} ]
do
while [ 1 -eq 1 ]
do
echo 'Do you want to unlock account ' ${arr[$i]} : '.Enter only Y/N:'
read arr_flag[$i]
if [ ${arr_flag[$i]} = 'Y' -o ${arr_flag[$i]} = 'N' ]
then
break
fi
done
#echo ${arr_flag[$i]} is the given flag
i=$i+1
done
i=0
echo "Below is the content after user response:"
while [ $i -lt ${#arr[*]} ]
do
print ${arr[$i]} : ${arr_flag[$i]}
(( i=i+1 ))
done
echo "Now unlocking the locked accounts which are with Y response"
i=0
while [ $i -lt ${#arr[*]} ]
do
if [ ${arr_flag[$i]} = 'Y' ]
then
print executing unlock for ${arr[$i]} : ${arr_flag[$i]}
echo "
set feedback off
set heading off
set pagesize 0
set serveroutput on
begin
execute immediate 'alter user ' || '${arr[$i]}' || ' account unlock ';
exception when others then
dbms_output.put_line('exception raised :' ||sqlcode );
dbms_output.put_line('exception raised :' ||sqlerrm );
end;
/
exit
" | sqlplus -s scott/tiger@testdb
else
print ${arr[$i]} : ${arr_flag[$i]} - NO UNLOCK required
fi
(( i=i+1 ))
done
|