【发布时间】:2016-09-26 17:11:18
【问题描述】:
我在使用期望脚本重置服务器数据库中的密码时收到以下消息。当我尝试重置包含“!”的密码时,我只会收到此错误。作为第一个字符。
[root@server]# ./changepw username !password!
-bash: !password!: event not found
我的脚本如下:
#!/usr/bin/expect -f
## Set up variables to be passed in as command line arguments
lassign $argv username password
spawn telnet 127.0.0.1 23
expect "200 PWD Server ready"
send "USER admin\r"
expect "300 please send the PASS"
send "PASS password\r"
expect "200 login OK, proceed"
# Use the line below for a password that must be quoted ie one that contains a $ or a ! by escaping the double quotes
send "SETACCOUNTPASSWORD $username PASSWORD \"$password\"\r"
expect "200 OK"
send "quit\r"
interact
当我在 CLI 脚本之外手动执行此操作并用引号将密码括起来时,这似乎确实有效。它只会因脚本而失败。
【问题讨论】:
-
与您的脚本无关。
event not found错误甚至在您的期望脚本启动之前发生 - 在此之前,shell 甚至会检查是否存在changepw命令。