-
Notifications
You must be signed in to change notification settings - Fork 154
/
current_users.ksh
64 lines (49 loc) · 1.37 KB
/
current_users.ksh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/ksh
# Script Name : current_users.ksh
# Author : Craig Richards(CR)
# Created : 21 July 2002
# Last Modified :
# Version : 1.0
# Modifications : 31-July-2002 (CR) Re-formatted the script to be inline with the template
# : 15-October-2002 (CR) Changed user script to identify more information
# Description : This will gather information about the users that are currently attached to the database.
#################################
# Start of procedures/functions #
#################################
funct_get_users()
{
sqlplus -s / as sysdba<< EOF
SET PAUSE OFF
SET PAGESIZE 200
SET LINESIZE 200
COLUMN username FORMAT A15
SPOOL $INFILE
select s.username, osuser, status, server as "Connect Type",
to_char(logon_time,'fmHH24:MI:SS AM') as "Logon Time",
sid, s.serial#, p.spid as "UNIX Proc"
from v\$session s, v\$process p
where s.paddr = p.addr
and s.username is not null
order by status, s.username, s.program, logon_time;
spool off
EXIT
EOF
}
funct_mail_file()
{
mailx -s " Current Users " $SALIST < $INFILE
}
################
# Main Program #
################
# Variable Settings
INFILE=/tmp/current_users.lst
SALIST='[email protected]'
# Oracle Environment
ORATAB_LOC=/etc/oratab ; export ORATAB_LOC
ORACLE_HOME=`sed /#/d ${ORATAB_LOC} | grep $ORACLE_SID | awk -F: '{print $2}'` ; export ORACLE_HOME
{
funct_get_users
funct_mail_file
}
## End of Script