I have written some script executable under root, where I need to su - oracle
from root, then source oraenv
and only then many other tasks follows. This is because all SIDs are running under oracle user, so the source oraenv
asks for SID and then sets the environment for this particular SID.
For this I am using expect within my BASH script very often.
Everything went fine until the moment the script was used on a system where there is this headache stuff within oracle's .profile and/or .bash_profile:
if [ -x /usr/bin/tabs ]
then
/usr/bin/tabs -8
fi
When making su - oracle
as a user, new blank line shows upon login:
server:(/root)(root)#su - oracle
Last login: Tue May 2 12:52:01 CEST 2023
server:(/home/oracle)(oracle)#
But what is worst - this produces following crazy characters just before any expect procedure with input parameters when expect stuff is called from within the script - for example:
' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' $'\EH' /usr/local/bin/oraenv R01 check status params /tmp/tmp.hUQAUljWdy /tmp/tmp.toszCySPhv /var/opt/script.log /opt
The line calling this expect function should look like this, of course, to get all the parameters correctly:
/usr/local/bin/oraenv R01 check status params /tmp/tmp.hUQAUljWdy /tmp/tmp.toszCySPhv /var/opt/script.log /opt
I have started by trying to define prompt within expect somehow to tell expect that the prompt could be so crazy, but I was not successfull.
Then I have tried to get rid of those tabs -8
lines from oracle .profile files (by replacing them with some echo to /dev/null) just before first expect is called from the script - to no avail. It seems like once the script starts, then when expect is called, the original .profile and/or bash_profile is source. This baffles me, because the script runs under the root user and switches under oracle later, only when needed. I have even tried to get rid of those tabs from profile files and do some 1st shot of expect with sourcing new profile files - so mimicking login to oracle user and thus source newly created .profile and bash_profile, but with the same results - crazy ?H
characters.
Have any of you needed to solve something similar? Any ideas?
Thanks a lot
According to this page, that's the VT100 escape sequence for setting a tab:
tabset HTS Set a tab at the current column ^[H
The simplest mechanisms for working around this (as it appears to be difficult to get the target system to stop calling /usr/bin/tabs
which is producing this output) is to either:
Set the TERM
environment variable to dumb
prior to spawn
ing the ssh
call. This should make tabs
believe it can't do anything.
set env(TERM) dumb
spawn ssh ...
Adapt your expect script to ignore all that stuff; expect is far more powerful than:
expect {
-re {.*\eH} exp_continue
"/usr/local/bin/oraenv"
}
Hopefully you don't need to do both of these!