This is the end goal: execute a mysql command using the expect script to send password when prompted. There are 3 files in total
test.sh (returns the password that is needed to connect to mysql database)
grep hibernate.connection.password /opt/cisco/cpam/properties/vx.hibernate.properties | sed 's/hibernate.connection.password=//g'
test1.sh (the mysql command that needs to be excecuted)
mysql -u cpam -p --protocol=tcp vxdb < /opt/cisco/cpam/import/MySQL_Views.sql
test.exp (the expect script that sends password while executing mysql command)
set password [exec ./test.sh]
expect "Enter password: "
In order for a program to be interactable-with via
send, you need to launch it with
spawn and not
exec. Try this:
set password [exec ./test.sh] spawn ./test1.sh expect "Enter password: " send "$password\r" expect eof