Исходник скрипта "olastlogon.sh":
#!/bin/bash
daScr=/tmp/script229.sql
echo SET LINESIZE 150\;>$daScr
echo SET PAGESIZE 300\;>>$daScr
echo select du.username\|\|case when du.account_status=\'OPEN\' then \'\' else \' \(\'\|\|du.account_status\|\|\'\)\' end USERNAME, max\(da.TIMESTAMP\) LASTLOGON>>$daScr
echo from dba_users du left join dba_audit_session da on da.username=du.username>>$daScr
echo where du.default_tablespace=\'USERS\'>>$daScr
echo group by du.username\|\|case when du.account_status=\'OPEN\' then \'\' else \' \(\'\|\|du.account_status\|\|\'\)\' end>>$daScr
echo order by 1 asc\;>>$daScr
echo exit\;>>$daScr
if [ $USER == root ]
then
su - oracle -c "sqlplus / as sysdba @$daScr"
else
sqlplus / as sysdba @$daScr
fi
rm $daScr
if [[ -n $DISPLAY ]]; then read -p 'Press ENTER key to exit.'; fi
Результат:
USERNAME LASTLOGON
ORACLE_BASE_1 29-AUG-14
ORACLE_BASE_2 18-JUL-14