一个expect自动登录问题解决

批量改配置的时候发现有些机器的密码第一位是 ‘-‘ 这样在expect的send 方法中会转为方法,这样造成了无法自动登录。出现的错误如下:

spawn ssh root@10.xx.xxx.xxx
": must be -i, -h, -s, -null, -0, -raw, -break, or —
while executing

"send_user "$PASSWORDr""
(file "./ssh_login" line 20)

google搜索下也没什么答案,只好看下man page,发现有这样一段

The — flag forces the next argument to be interpreted as a string rather than a flag. Any string can be preceded by "–"

whether or not it actually looks like a flag. This provides a reliable mechanism to specify variable strings without being
tripped up by those that accidentally look like flags. (All strings starting with "-" are reserved for future options.)

于是改成 send — "$PASSWORDr"; 就解决了。

###########################################

Best regards
Timo Seven
blog: http://www.timoseven.com
twitter: http://twitter.com/zauc
Linux System Admin & MySQL DBA

关于 Timo
XNIX SA & MYSQL DBA

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: