Expect script that tests if a passwordless connection is setup
A couple of notes:

expect is an extension of Tcl, so you can use any Tcl command: http://www.tcl-lang.org/man/tcl8.6/TclCmd/contents.htm

specifically, you could write
lassign $argv user server

which is arguably a bit less readable, but is only one command.


You can speed up the timeouts: the default is 10 seconds, and you probably don't want to wait for 20 seconds to get the final exit status:
set timeout 1   ;# in seconds


you never reset the rc variable, and the default exit status is zero already, so you can remove set rc 0 and exit $rc

expect is not bash: you don't need to quote all the variables.

you don't need to reset log_user just before exiting the script.

expect code written in this style can get pretty deeply nested: The last pattern in an expect command does not need an action block
expect {
  $pwd_prompt  { exit 1 }
  eof          { exit 2 }
  timeout      { exit 3 }
  $prompt     
}
send &quot;hostname\r&quot;
expect {
  *$server*    { exit 0 }
  eof          { exit 4 }
  timeout      { exit 5 }
}

If $prompt is seen, then that expect command ends, and the script continues with send