我以非常传统的匹配字符串方式使用expect,在围绕iplanet / SJWS wadm命令的bash脚本中发送所需的输入,该命令本身是一个调用java程序的bash脚本。
而不是当我手动运行程序时,某些组件(如密码)会回显到shell,并且控制字符似乎不会被发送。
我认为它可能是一个多行正则表达式问题,但在期望的前面使用通配符似乎不起作用,并且使用调试选项(在发送密码字符串时)期望比较密码我希望与之匹配的字符串。
我没有太多的期待经验,希望以前有人见过这个问题。
由于
答案 0 :(得分:1)
假设:
wadm
脚本的路径运行以下脚本; 这可能符合您的需求:
<强> reset.exp 强>
#!/usr/bin/expect
if {$argc != 1} {
puts "Usage: expect $argv0 password"
exit 1
}
set PASSWD [lindex $argv 0] ;# get password from the first argument
spawn -noecho $env(SHELL) ;# spawn a new process, in order to use send/expect
set timeout 10 ;# short one (10 s)
log_user 0 ;# disable showing up sensitive info (PASSWD value)
set cmd "wadm reset-admin-password" ;# put the command string into a variable
send "$cmd\r"
expect {
-regex "enter admin-password.*$" {
puts "Got the password request ..."
}
timeout {
puts "ERROR: Timeout reached during running $cmd !"
exit 1
}
}
send "$PASSWD\r"
expect {
-regex "enter admin-password again.*$" {
send "$PASSWD\r"
expect -re ".*$"
# TODO: define reject/accept patterns
puts "Password accepted!"
}
timeout {
puts "ERROR: Timeout reached on entering password!"
exit 1
}
}
send "exit\r"
expect eof
答案 1 :(得分:0)
并设法解决问题,wadm命令似乎会使肥皂连接速度减慢,所以
/usr/bin/expect << EOD
set password $PASSWD
spawn $BINDIR/wadm reset-admin-password
sleep 1
expect -re ".*admin-password> " {send -- "$password\r"}
expect -re ".*admin-password again> " {send -- "$password\r"}
expect -re ".*CLI" {send -- "exit\r"}
interact
EOD
感谢您的帮助!