Connecting to multiple instances on the same server

I have a db server with two instances...trying to create an expect script that will scan both the listener and the alert log files and retrieve their sizes.
Issue we have is that the .profile is hard coded with one of the databases name and script is always pulling from the same instance ( testdb1 ) instead of skipping to the next one ( testdb2 ).
We need help on modding the script to pull from testdb1 then connect and put from testdb2 because the paths are different.

these are the settings below.

# 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=/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;"

# add env setting command for db01 server TEST DB2
 set v_command_db01_testdb2 "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=RCDB:/oraclet/120;export ORACLE_SID=TESTDB2;"

I need help with this please...so far i cannot get the script to pull from the testdb2 ...the sid is always set to testbd1 and thus pulling the wrong files...their paths are different.

PROVIDING MORE CLARITY TO MY PREVIOUS POSTING...

I have a db server with two instances...trying to create an expect script that will scan both the listener and the alert log files and retrieve their sizes.
Issue we have is that the .profile is hard coded with one of the databases name and script is always pulling from the same instance (testdb1) instead of skipping to the next one (testdb2).
We need help on modding the script to pull from testdb1 then connect and put from testdb2 because the paths are different.

these are the settings below.

# 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=/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;"

# add env setting command for db01 server TEST DB2
set v_command_db01_testdb2 "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=RCDB:/oraclet/120;export ORACLE_SID=TESTDB2;"

-----------------
spawn output.... the second run sets the sid to hm
----------------------------------------------------------------------------------------------------------------------------------

running ssh oraclet@db01...
spawn ssh oraclet@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 ----------------------------------------------------------------------------------------------------------------------------------
Warning!! Authorized users only. All activity may be monitored and reported.
Password:
hostname:server1
            Alert Log: /oraclet/diag/rdbms/testdb1/TESTDB1/trace/alert_TESTDB1.log - 2 (KB)
            Listener Log: /oraclet/diag/tnslsnr/server1/listener/trace/listener.log - 153742 (KB)
----------------------------------------------------------------------------------------------------------------------------------
running ssh oraclet@server1...
spawn ssh oraclet@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_RCDB.log | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESDB2.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 ----------------------------------------------------------------------------------------------------------------------------------
Warning!! Authorized users only. All activity may be monitored and reported.
Password:
hostname:hatstdb01
            Alert Log: /oraclet/diag/rdbms/rcdb/TESTDB2/trace/alert_TESTDB2.log - 770 (KB)
            Listener Log: /oraclet/diag/tnslsnr/hatstdb01/listener/trace/listener.log - 153742 (KB)

**********The output is suppose to read as follows...**************Because the path to the listener logs are different between TESTDB1 and TESTDB2

            Alert Log: /oraclet/diag/rdbms/rcdb/TESTDB2/trace/alert_TESTDB2.log - 770 (KB)
            Listener Log: /oraclet/diag/tnslsnr/hatstdb01/listener_TESTDB2/trace/listener.log - 153742 (KB)

---------- Post updated at 02:46 PM ---------- Previous update was at 12:50 PM ----------

I have a db server with two instances...trying to create an expect script that will scan both the listener and the alert log files and retrieve their sizes.
Issue we have is that the .profile is hard coded with one of the databases name and script is always pulling from the same instance (testdb1) instead of skipping to the next one (testdb2).
We need help on modding the script to pull from testdb1 then connect and put from testdb2 because the paths are different.

these are the settings below.

[# 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=/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;"]

[# add env setting command for db01 server TEST DB2
set v_command_db01_testdb2 "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=RCDB:/oraclet/120;export ORACLE_SID=TESTDB2;"]

-----------------
spawn output.... the second run sets the sid to hm
----------------------------------------------------------------------------------------------------------------------------------
[running ssh oraclet@db01...
spawn ssh oraclet@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] ----------------------------------------------------------------------------------------------------------------------------------
[Warning!! Authorized users only. All activity may be monitored and reported.
Password:
hostname:server1
Alert Log: /oraclet/diag/rdbms/testdb1/TESTDB1/trace/alert_TESTDB1.log - 2 (KB)
Listener Log: /oraclet/diag/tnslsnr/server1/listener/trace/listener.log - 153742 (KB)]
----------------------------------------------------------------------------------------------------------------------------------
[running ssh oraclet@server1...
spawn ssh oraclet@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_RCDB.log | tr '\n' ' '; echo '-' | tr '\n' ' ' ; du -sk /oraclet/diag/rdbms/testdb2/TESTDB2/trace/alert_TESDB2.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] ----------------------------------------------------------------------------------------------------------------------------------
[Warning!! Authorized users only. All activity may be monitored and reported.
Password:
hostname:hatstdb01
Alert Log: /oraclet/diag/rdbms/rcdb/TESTDB2/trace/alert_TESTDB2.log - 770 (KB)
Listener Log: /oraclet/diag/tnslsnr/hatstdb01/listener/trace/listener.log - 153742 (KB)]

**********this is suppose to read as follows...**************Because the path to the listener logs are different between TESTDB1 and TESTDB2]

      [  Alert Log: /oraclet/diag/rdbms/rcdb/TESTDB2/trace/alert_TESTDB2.log - 770 \(KB\)
        Listener Log: /oraclet/diag/tnslsnr/hatstdb01/listener_TESTDB2/trace/listener.log - 153742 \(KB\)