calling an expect script from another script (sh)
How to call the EXPECT utility from SHELL script?
Our objective is - We have developed a shell script to connect the oracle database and generate the XML file and this XML file needs to be transfer to another windows machine using the SFTP servcies. We are planning to schedule this job using the CRONTAB.
-
Our first script 1:
----------------
# connecting to oracle database and generating the file
ORACLE_SID=TEST
ORACLE_HOME=/u01/oratest/db/tech_st/11.1.0
export ORACLE_SID ORACLE_HOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib
PATH=$ORACLE_HOME/bin:$PATH
output=`sqlplus -s /nolog <<EOT
set pages 0 feed off
whenever sqlerror exit failure;
connect xgbzprod/xgbzprod
exec XGBZ_GL_COA_XMLTAG_PROC;
EOT
`
cd /u01/oratest/gebiz_processed
for fn in GEBIZ_COA_RPO000*.*; do
# using the EXPECT utility to transfer the generated file to antoher machine
set timeout 10
spawn $env(SHELL)
match_max 100000
send -- "sftp username@IP Address\r"
expect -exact "testing123@10.1.2.3's password:"
send -- "Password\r"
expect -exact "sftp>"
send -- "cd /<SFTP location>\r"
expect -exact "sftp>"
send -- "lcd /<Local locatoin>\r"
expect -exact "sftp>"
send -- "bin\r"
send -- "put $fn\r"
expect -exact "sftp>"
send -- "quit\r"
send -- "exit\r"
expect eof
-- When we run the above script it failes and the script is not recognizing the other variables.
-- We have split the procedure to keep the oracle connection in one script and another script for EXPECT utility. But we are lack of how to call the EXPECT utility in shell script.
Please help us
Thank
Dhanraj Chilla