简体   繁体   English

期望与SJWS wadm命令

[英]Expect with SJWS wadm command

I'm using expect in the very traditional way of match string, send desired inputs within a bash script wrapping around iplanet/SJWS wadm command, which itself is a bash script calling a java program. 我正在以传统的匹配字符串方式使用Expect,在围绕iplanet / SJWS wadm命令的bash脚本中发送所需的输入,该脚本本身就是一个调用Java程序的bash脚本。

Rather than when I run the program manually, certain components such as passwords get echoed back to the shell and the control characters don't seem to be sent. 而不是当我手动运行程序时,某些组件(例如密码)会回显到外壳,并且似乎不会发送控制字符。

I think it might be a multiline regexp issue, but using a wildcard at the front of the expect doesn't seem to work, and using the debug option (when sending a password string) has the expect comparing the password with the string I want to match it to. 我认为这可能是多行正则表达式问题,但是在期望的前面使用通配符似乎不起作用,并且使用调试选项(在发送密码字符串时)希望将密码与我想要的字符串进行比较匹配它。

I don't have much experience with expect and was hoping if anyone had seen this issue before. 我没有太多期望的经验,希望有人以前见过这个问题。

Thanks 谢谢

Assuming that: 假如说:

  • you are using Unix environment; 您正在使用Unix环境;
  • you have no problems running an expect file, instead of expect one-liners; 您运行期望文件而不是期望单行没有问题;
  • you run the following script from the path in which wadm script is found; 您从找到wadm脚本的路径中运行以下脚本;

This will probably suit your needs: 这可能会满足您的需求:

reset.exp 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

And managed to get things resolved, the wadm command appears to make a soap connection that slows things down, so 并设法解决问题后,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

Thanks for the help! 谢谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM