2016-09-26 221 views
0

使用期望脚本重置服务器数据库中的密码时,出现以下消息。当我尝试重置包含“!”的密码时,我只出现此错误。作为第一个字符。Expect脚本:传递参数时出现“event not found”

[[email protected]]# ./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同时放入引号内的密码工作。它只与脚本失败。

+0

与您的脚本无关。事件未发现错误发生在你期望的脚本开始之前 - 在此之前,shell甚至检查是否存在'changepw'命令。 –

回答

1

这完全不是您期望的脚本的问题,而是您运行它的交互式shell的问题:在启用了历史记录展开的交互式shell中,!foo(非数值参数foo)指从foo开始的历史中最近的命令。


使用set +H关闭历史扩展(在你的~/.bashrc如果你想它的off-by-默认),或者把你的周围惊叹号单引号:

set +H       # turn off history expansion... 
./changepw username !password! # ...and this will now work 

...或者。 ..

./changepw username '!password!' # or just add quotes