linux - Execute sudo using expect inside ssh from bash -


i want create script automates installation on multiple linux hosts. login hosts using ssh keys , inside login want sudo, trying use expect, have on stations i don't have on server runs script. how do this, try, no luck it:

#!/bin/bash   ssh user@station04 <<eof expect -d -c " send \"sudo ls\" expect {         \"password:\" { send '1234'; exp_continue }         \"$user@\"{                 send "exit\r"         }         default {exit 1} }" eof   exit 

the result:

send: sending "sudo ls" { exp0 }  expect: "" (spawn_id exp0) match glob pattern "password:"? no expect: read eof expect: set expect_out(spawn_id) "exp0" expect: set expect_out(buffer) "" argv[0] = expect  argv[1] = -d  argv[2] = -c  argv[3] =  send "sudo ls\r" expect {     "password:" { send '1234';  exp_continue }     "@"{         send exitr     }     default {exit 1} }   set argc 0 set argv0 "expect" set argv "" 

a.k

what this? <- make sure of expected prompts.

#!/bin/bash  expect <<'end' spawn ssh user@station04 expect "password:" send "$pw\r" expect "#" send "sudo ls\r"  end 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -