Jerald Valmoria Jerald Valmoria - 11 months ago 93
Linux Question

Run bash script inside the expect script

Im trying to run my bash script inside an expect script but getting errors.

/usr/bin/expect <<EOD
spawn ssh nginubud@ $(<
expect "assword:"
send "$reg\r"
expect eof

im trying to do this in expect
ssh nginubud@ "$(<"
, this one is working but i need to find a way to run it in automated way. I dont want to use RSA keys.

error that in encountered:

spawn ssh nginubud@ #tats script
invalid command name "echo"
while executing
"echo "Enter Year:""

Also i can run my expect ssh script but when i include and try to run my
im getting "no variable errors"

Answer Source

You can use ssh user@host bash -c .... For example:

[bash] % cat
export CMD=$( printf '%q' "$(<" )
expect << EOF
spawn ssh foo@localhost bash -c \$::env(CMD)
expect -nocase password:
send bar\r
expect eof
[bash] % cat
echo hello world | tr a-z A-Z
[bash] % bash
spawn ssh foo@localhost bash -c echo\ hello\ world\ \|\ tr\ a-z\ A-Z
foo@localhost's password:
[bash] %