主要是需要支持set autotrace traceonly;select * from xxxx;这种的需要前后session保持的语句,比较恶心点。
#!/usr/bin/expect
#
# Descript: A interface to receive and run sql from web
# And turn back data to web
#
# Require: expect,sqlplus
#
# Author: suddy
#
# Data: 2010-01-04
#
###########################################
#usage: ./websqlplus.exp username password sql
# e.g.
# ./websqlplus.exp suddy suddy "set autotrace traceonly;select * from ABC_SDA_USERS;"
#
set user [lindex $argv 0]
set pass [lindex $argv 1]
set sqls [lindex $argv 2]
if {$argc==3} {
spawn sqlplus /nolog
expect ">"
send "conn $user/$pass\r"
foreach sqlcommon [split "$sqls" ";"] {
if {$sqlcommon!=""} {
expect ">"
send "$sqlcommon;\r";
}
}
expect ">"
send "quit;\r"
}
附上代码保存一份
再次痛恨expect的语法。。。。。