Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with this script so that it can pull info from the two different instances!!

Status
Not open for further replies.

michealbantor

Technical User
May 25, 2018
6
US
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/ucb:pATH:.;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/ucb:pATH:.;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)]
 
like the output to be in MB

add -h to the du command (-h being the option for "human readable" byte sizes, so it becomes
Code:
du -skh


Here again the manual for du
Code:
man 1 du
will tell you what the options are for the command.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
My issue is not with the 'du command', the really issue is with selecting the correct instance/database name from a server running two instances or databases....
[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/ucb:pATH:.;export ORACLE_HOME=/oraclet/120;[highlight yellow]export ORACLE_SID=TESTDB1[/highlight];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' ' ' ;]
- because it set the same sid in the second script...it is supposed to select testdb1 and then next script selects testdb2.!!
 
My issue is not with the 'du command'

That's why I quoted the bit of your questions I was providing the answer to.


The rest, ... I have no idea, as I said in your other thread on the topic, I don't 'do' Oracle.

But at an semi educated guess, you probably need change the values as necessary before the second script runs.


but you probably might want to assist us by wrapping your script parts in code tags so it is much more readable.
Click the 'help' icon to the left of the preview button to find out how.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top