-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcurrent users.ksh
49 lines (38 loc) · 882 Bytes
/
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
#!/bin/ksh
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