Reputation: 291
#!/bin/bash
/usr/bin/expect << SSHLOGIN
spawn ssh -o StrictHostKeyChecking=no admin@$host
expect {
Password: {
send "Pass$word\n"
expect {
OK: {
send "xstatus\n"
send "quit\n"
}
}
}
}
SSHLOGIN
It is not able to ssh because it is not escaping the '$' character in "Pass$word\n" since $ is part of the password and there is no variable being passed. How would you escape it? I know in bash, you would add '\', but since the password is in the expect script portion, that does not work.
EDIT:
changing Pass$word\n
to Pass\\\$word\n
works
Upvotes: 1
Views: 4402
Reputation: 123460
Here-documents are bash code, so you'd still use \$
.
The expect script is TCL, so you'll need to escape the $
there too. With two levels of escaping, you get:
send "Pass\\\$word\n"
Upvotes: 2