一个expect自动登录问题解决
批量改配置的时候发现有些机器的密码第一位是 ‘-‘ 这样在expect的send 方法中会转为方法,这样造成了无法自动登录。出现的错误如下:
spawn ssh [email protected] ": 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