为满足客户需求,以下是使用shell脚本做交互的简单示例,发出来做记录,方便以后使用。
#!/bin/bash
pwd=lg ##注意,设置变量时前面不能有set,且expect放在shell脚本中,expect里的set命令也无法识别。
/usr/bin/expect <<EOF
set timeout 10
spawn sqlplus -S / as sysdba
expect "SQL>"
send "conn\r"
expect "Enter user-name:"
send "lg\r"
expect "Enter password:"
send "$pwd\r"
expect "Connected"
send "select table_name from user_tables;\r"
send "quit;\r"
expect eof
EOF