На работе мне приходится каждый день запускать следующую функцию. Функция работает нормально, когда мне предлагают пароль. Однако я попытался жестко закодировать свой пароль, чтобы не вводить его каждый день. Это не работает Любые намеки на то, почему?
function update()
{
firewalluser=`whoami`
# -s => silent (no echo of characters), -p => prompt user
#read -s -p "Password: " firewallpass
firewallpass="mypassword"
TRUSTED=(
xxx.yyy.com
jenkins.xxx.com
svn.xxx.com
)
for server in ${TRUSTED[*]}
do
echo ""
echo "--> connecting to $server"
expect <<EOF
set timeout 20
spawn telnet $server
expect "Username: "
send "$firewalluser\r"
expect "Password: "
send "$firewallpass\r"
expect "Firewall User Authentication: Accepted"
send "exit"
exit
EOF
done
}
Я запускаю это в GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin13)
с функцией, определенной в моем .bash_profile
.
Заранее спасибо.
РЕДАКТИРОВАТЬ: я добавил exp_internal 1
и вот ответ от программы:
--> connecting to some.domain.name.com
spawn telnet some.domain.name.com
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {64289}
expect: does "" (spawn_id exp7) match glob pattern "Username: "? no
Trying xx.yy.zz...
expect: does "Trying xx.yy.zz...\r\n" (spawn_id exp7) match glob pattern "Username: "? no
Connected to some.domain.name.com.
Escape character is '^]'.
expect: does "Trying xx.yy.zz...\r\nConnected to some.domain.name.com.\r\nEscape character is '^]'.\r\n" (spawn_id exp7) match glob pattern "Username: "? no
Please Authenticate to VSD DR2
Username:
expect: does "Trying xx.yy.zz...\r\nConnected to some.domain.name.com.\r\nEscape character is '^]'.\r\nPlease Authenticate to VSD DR2\r\nUsername: " (spawn_id exp7) match glob pa\
tern "Username: "? yes
expect: set expect_out(0,string) "Username: "
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "Trying xx.yy.zz...\r\nConnected to some.domain.name.com.\r\nEscape character is '^]'.\r\nPlease Authenticate to VSD DR2\r\nUsername: "
send: sending "nklosterman\r" to { exp7 }
expect: does "" (spawn_id exp7) match glob pattern "Password: "? no
Password:
expect: does "\r\nPassword: " (spawn_id exp7) match glob pattern "Password: "? yes
expect: set expect_out(0,string) "Password: "
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "\r\nPassword: "
send: sending "mypassword!\r" to { exp7 }
expect: does "" (spawn_id exp7) match glob pattern "Firewall User Authentication: Accepted"? no
Firewall User Authentication: Failed
expect: does "\nFirewall User Authentication: Failed\r\n" (spawn_id exp7) match glob pattern "Firewall User Authentication: Accepted"? no
Connection closed by foreign host.
expect: does "\nFirewall User Authentication: Failed\r\nConnection closed by foreign host.\r\n" (spawn_id exp7) match glob pattern "Firewall User Authentication: Accepted"? no
expect: read eof
expect: set expect_out(spawn_id) "exp7"
expect: set expect_out(buffer) "\nFirewall User Authentication: Failed\r\nConnection closed by foreign host.\r\n"
send: sending "exit" to { exp7 send: spawn id exp7 not open
while executing
"send "exit""
Я вижу, что мой пароль отправляется с добавленным к нему символом \r. Я не уверен, почему он не принимает это. Я даже пытался жестко закодировать свой пароль в heredoc вместо установки переменной, и это не сработало.