ubuntu 14.04 - use expect to enter password when need sudo in script -
i using ubuntu 14.04 , installed expect. trying write script enter password when prompted.
updated code:
#!/usr/bin/expect -d set timeout 20 set pw odroid spawn sudo apt-get update expect {\[sudo]\ password odroid: } send "$pw\r" close
any suggestions? thx
update errors:
expect: "" (spawn_id exp4) match glob pattern "\[sudo]\ password odroid: "? no [sudo] password odroid: expect: "[sudo] password odroid: " (spawn_id exp4) match glob pattern "\[sudo]\ password odroid: "? yes expect: set expect_out(0,string) "[sudo] password odroid: " expect: set expect_out(spawn_id) "exp4" expect: set expect_out(buffer) "[sudo] password odroid: " send: sending "odroid\r" { exp4 }
you have many quotes. choose 1 of:
expect {\[sudo\] password odroid: } expect "\\\[sudo\\\] password odroid: "
clearly first option better.
lots of escaping necessary because 1) square brackets special in glob pattern, , 2) square brackets special tcl syntax (command substitution) in double quotes not in curly braces.
Comments
Post a Comment