michealbantor
Technical User
This expect script is suppose to connect to SERVER DB01 that hosts two databases and pull the alert and listener log files sizes. The problem i am having is that the correct alert log/size file is pulled for both databases but the wrong listener log/size is pulled for testdb2...because in the output (below) the sid is set to testdb1 instead of testdb2. I need help in directing the script ot set the correct sid and to pull from the correct path for testdb2. I will also like the output to be in MB because i only want to print out the log files larger that 500MB and mail them out every day , then every friday i mail out the complete output.
#!/usr/bin/expect -f
# Expect script to supply Oracle admin password for remote ssh server
# and execute command.
# This script needs three argument to(s) connect to remote server:
[# set Variables]
[set v_password [lrange $argv 0 0]
[set v_server [lrange $argv 1 1]
[set v_user [lrange $argv 2 2]
[set v_alert [lrange $argv 3 3]
[set v_alert2 [lrange $argv 4 4]
[set v_host_db01 "10.10.80.34"]
[set v_user_oraclem "oraclem"]
[# command for gathering hostname
set v_host_command "echo hostname | tr '\\n' ':' ;hostname"]
[# Exception hostname
set v_host_null "echo''"]
[# command for gathering Listener Log
set v_listener_command "; echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g'` | awk '{ print \$1 }' | tr '\\n' ' ' ; echo '(KB)'"]
# add env setting command for db01 server TEST DB
[#set v_command_db01_testdb1 "export PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/users/oraclet/bin:/usr/bin/X11:/sbin:/usr/ccs/bin:/bin:/usr/local/bin:.:/oraclet/120/bin:/oraclet/120;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB1;"]
[# add env setting command for db01 server Catalog
set v_command_db01_testdb2 "export PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/users/oraclet/bin:/usr/bin/X11:/sbin:/usr/ccs/bin:/bin:/usr/local/bin:.:/oraclet/120/bin:/oraclet/120;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB2;"]
[# add env listener command for db01 server TEST DB
set v_listener_db01_1 "; echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; echo '/oraclet/diag/tnslsnr/db01/listener/trace/listener.log' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk /oraclet/diag/tnslsnr/db01/listener/trace/listener.log | awk '{print \$1 }' | tr '\\n' ' ' ; echo '(KB)'"]
[# add listener command for db01 server RMAN Catalog
set v_listener_db01_testdb1 "; echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; echo '/oraclet/diag/tnslsnr/db01/listener_testdb2/trace/listener_TESTDB2.log' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk /oraclet/diag/tnslsnr/db01/listener_testdb2/trace/listener_TESTDB2.log | awk '{print \$1 }' | tr '\\n' ' ' ; echo '(KB)'"]
[# now connect to remote UNIX box
} elseif {$v_server == $v_host_db01 && $v_user == $v_user_oraclet} {
spawn ssh $v_user@$v_server $v_command_db01_testdb1$v_host_command$v_exc_alert_command$v_listener_db01_1$v_end_command
match_max 100000]
[} elseif {$v_server == $v_host_db01 && $v_user == $v_user_oraclet} {
spawn ssh $v_user@$v_server $v_command_db01_testdb2$v_host_command$v_exc_alert_command$v_listener_db01_b$v_end_command
match_max 100000]
[# Look for passwod prompt
expect "*?assword:*"]
[# Send password
send "$v_password\r"]
[# send blank line (\r) to make sure we get back to gui
send "\r"
expect eof]
[running ssh oraclem@db01...
spawn ssh oraclem@db01 export PATH=/oraclet/120/bin:/usr/bin:/usr/ccs/bin:/usr/vac/bin:/usr/sbin:/sbin:/usr/bin/X11:/bin:/usr/local/bin:/usr/lbin:/usr/ucbATH:.;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB1;echo hostname | tr '\n' ':' ;hostname; echo ' Alert Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ;echo /oraclet/diag/rdbms/testdb1/TESTDB1/trace/alert_TESTDB1.log | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk /oraclet/diag/rdbms/testdb1/TESTDB1/trace/alert_TESTDB1.log | awk '{ print $1 }'| tr '\n' ' ' ; echo '(KB)'; echo ' Listener Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ; lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g' | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g'` | awk '{ print $1 }' | tr '\n' ' ' ; echo '(KB)';echo] [----------------------------------------------------------------------------------------------------------------------------------]
[Password:
hostname:db01
Alert Log: /oraclet/diag/rdbms/TESTDB1/TESTDB1/trace/alert_TESTDB1.log - 3 (KB)
Listener Log: /oraclet/diag/tnslsnr/db01/listener/trace/listener.log - 154255 (KB)]
[----------------------------------------------------------------------------------------------------------------------------------]
[running ssh oraclem@db01...(in this output its setting and connecting the the wrong sid ...testdb1...needs to be connecting to testdb2)
spawn ssh oraclem@db01 export PATH=/oraclet/120/bin:/usr/bin:/usr/ccs/bin:/usr/vac/bin:/usr/sbin:/sbin:/usr/bin/X11:/bin:/usr/local/bin:/usr/lbin:/usr/ucbATH:.;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB1;echo hostname | tr '\n' ':' ;hostname; echo ' Alert Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ;echo /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESTDB2.log | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESTDB2.log | awk '{ print $1 }'| tr '\n' ' ' ; echo '(KB)'; echo ' Listener Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ; lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g' | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g'` | awk '{ print $1 }' | tr '\n' ' ' ; echo '(KB)';echo]
[----------------------------------------------------------------------------------------------------------------------------------]
[Password:
hostname:db01
Alert Log: /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESTDB2.log - 770 (KB)
Listener Log: /oraclet/diag/tnslsnr/db01/listener/trace/listener.log - 154255 (KB)]
[Listener Log: /oraclet/diag/tnslsnr/db01/listener_testdb2/trace/listener_TESTDB2.log - 154255 (KB)]
#!/usr/bin/expect -f
# Expect script to supply Oracle admin password for remote ssh server
# and execute command.
# This script needs three argument to(s) connect to remote server:
[# set Variables]
[set v_password [lrange $argv 0 0]
[set v_server [lrange $argv 1 1]
[set v_user [lrange $argv 2 2]
[set v_alert [lrange $argv 3 3]
[set v_alert2 [lrange $argv 4 4]
[set v_host_db01 "10.10.80.34"]
[set v_user_oraclem "oraclem"]
[# command for gathering hostname
set v_host_command "echo hostname | tr '\\n' ':' ;hostname"]
[# Exception hostname
set v_host_null "echo''"]
[# command for gathering Listener Log
set v_listener_command "; echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print \$4 }' | sed 's/alert\\/log.xml/trace\\/listener.log/g'` | awk '{ print \$1 }' | tr '\\n' ' ' ; echo '(KB)'"]
# add env setting command for db01 server TEST DB
[#set v_command_db01_testdb1 "export PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/users/oraclet/bin:/usr/bin/X11:/sbin:/usr/ccs/bin:/bin:/usr/local/bin:.:/oraclet/120/bin:/oraclet/120;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB1;"]
[# add env setting command for db01 server Catalog
set v_command_db01_testdb2 "export PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/users/oraclet/bin:/usr/bin/X11:/sbin:/usr/ccs/bin:/bin:/usr/local/bin:.:/oraclet/120/bin:/oraclet/120;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB2;"]
[# add env listener command for db01 server TEST DB
set v_listener_db01_1 "; echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; echo '/oraclet/diag/tnslsnr/db01/listener/trace/listener.log' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk /oraclet/diag/tnslsnr/db01/listener/trace/listener.log | awk '{print \$1 }' | tr '\\n' ' ' ; echo '(KB)'"]
[# add listener command for db01 server RMAN Catalog
set v_listener_db01_testdb1 "; echo ' Listener Log' | tr '\\n' ':'; echo '' | tr '\\n' ' ' ; echo '/oraclet/diag/tnslsnr/db01/listener_testdb2/trace/listener_TESTDB2.log' | tr '\\n' ' '; echo '-' | tr '\\n' ' ' ; du -sk /oraclet/diag/tnslsnr/db01/listener_testdb2/trace/listener_TESTDB2.log | awk '{print \$1 }' | tr '\\n' ' ' ; echo '(KB)'"]
[# now connect to remote UNIX box
} elseif {$v_server == $v_host_db01 && $v_user == $v_user_oraclet} {
spawn ssh $v_user@$v_server $v_command_db01_testdb1$v_host_command$v_exc_alert_command$v_listener_db01_1$v_end_command
match_max 100000]
[} elseif {$v_server == $v_host_db01 && $v_user == $v_user_oraclet} {
spawn ssh $v_user@$v_server $v_command_db01_testdb2$v_host_command$v_exc_alert_command$v_listener_db01_b$v_end_command
match_max 100000]
[# Look for passwod prompt
expect "*?assword:*"]
[# Send password
send "$v_password\r"]
[# send blank line (\r) to make sure we get back to gui
send "\r"
expect eof]
[running ssh oraclem@db01...
spawn ssh oraclem@db01 export PATH=/oraclet/120/bin:/usr/bin:/usr/ccs/bin:/usr/vac/bin:/usr/sbin:/sbin:/usr/bin/X11:/bin:/usr/local/bin:/usr/lbin:/usr/ucbATH:.;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB1;echo hostname | tr '\n' ':' ;hostname; echo ' Alert Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ;echo /oraclet/diag/rdbms/testdb1/TESTDB1/trace/alert_TESTDB1.log | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk /oraclet/diag/rdbms/testdb1/TESTDB1/trace/alert_TESTDB1.log | awk '{ print $1 }'| tr '\n' ' ' ; echo '(KB)'; echo ' Listener Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ; lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g' | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g'` | awk '{ print $1 }' | tr '\n' ' ' ; echo '(KB)';echo] [----------------------------------------------------------------------------------------------------------------------------------]
[Password:
hostname:db01
Alert Log: /oraclet/diag/rdbms/TESTDB1/TESTDB1/trace/alert_TESTDB1.log - 3 (KB)
Listener Log: /oraclet/diag/tnslsnr/db01/listener/trace/listener.log - 154255 (KB)]
[----------------------------------------------------------------------------------------------------------------------------------]
[running ssh oraclem@db01...(in this output its setting and connecting the the wrong sid ...testdb1...needs to be connecting to testdb2)
spawn ssh oraclem@db01 export PATH=/oraclet/120/bin:/usr/bin:/usr/ccs/bin:/usr/vac/bin:/usr/sbin:/sbin:/usr/bin/X11:/bin:/usr/local/bin:/usr/lbin:/usr/ucbATH:.;export ORACLE_HOME=/oraclet/120;export ORACLE_SID=TESTDB1;echo hostname | tr '\n' ':' ;hostname; echo ' Alert Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ;echo /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESTDB2.log | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESTDB2.log | awk '{ print $1 }'| tr '\n' ' ' ; echo '(KB)'; echo ' Listener Log' | tr '\n' ':'; echo '' | tr '\n' ' ' ; lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g' | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk `lsnrctl status | grep Log | awk '{ print $4 }' | sed 's/alert\/log.xml/trace\/listener.log/g'` | awk '{ print $1 }' | tr '\n' ' ' ; echo '(KB)';echo]
[----------------------------------------------------------------------------------------------------------------------------------]
[Password:
hostname:db01
Alert Log: /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESTDB2.log - 770 (KB)
Listener Log: /oraclet/diag/tnslsnr/db01/listener/trace/listener.log - 154255 (KB)]
[Listener Log: /oraclet/diag/tnslsnr/db01/listener_testdb2/trace/listener_TESTDB2.log - 154255 (KB)]