- 论坛徽章:
- 0
|
1、use shell script to execute sql statement and output to a local file with sqlplus;- #!/bin/sh
- tempfile=./tmp/audit_locked_accounts_$ORACLE_SID.txt
- # Start sqlplus and check for locked accounts
- sqlplus -S users/password@dblink << EOF >$tempfile
- set pagesize
- select 'The following accounts were found to be unlocked and should not be'
- from dual;
- define exit_status = 0
- column xs new_value exit_status
- select username, account_status, 1 as xs from dba_users
- where account_status != 'LOCKED'
- and username in ('HR','SCOTT','OUTLN', 'MDSYS', 'CTXSYS');
- exit &exit_status
- EOF
- # If the exit status of sqlplus was not 0 then we will send an email
- if [ $? != 0 ]
- then
- mail -s "Accounts Unlocked in $ORACLE_SID" oracle < $tempfile
- fi
复制代码 |
|