Skip to content
Advertisement

issue in logging in as sudo user

here is the script sample.expect :

#!/usr/bin/expect
spawn ssh -t USER@HOST "sudo su "
expect "USER@HOST's password:"
send "passwordr"
expect "$ "
expect "[sudo] password for USER:"
send "passwordr"
expect "$ "
puts "USER [exec whoami]"
interact


-bash-4.1$ expect sample.expect`enter code here`
spawn ssh -t USER@HOST sudo su root
FIPS integrity verification test failed.
USER@HOST's password:
[sudo] password for USER: invalid command name "sudo"
    while executing
"sudo"
    invoked from within
"expect "[sudo] password for USER:""
    (file "sample.expect" line 6)
-bash-4.1$

expecting to log into the host as sudo user. but getting issue [sudo] password for USER: invalid command name “sudo” while executing “sudo” invoked from within “expect “[sudo] password for USER:”” (file “sample.expect” line 6).

Advertisement

Answer

expect "[sudo] password for USER:"

That uses square brackets, which are Tcl’s mechanism for command substitition. You have to either escape the leading bracket, or use Tcl’s non-interpolating quotes: one of

expect "[sudo] password for USER:"
# or
expect {[sudo] password for USER:}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement