command execute with error when use expect in shell script while work fine in pure shell

  bash, docker, expect

i try to start all the exited docker containers deployed in separated servers, so basically i should execute the essential command below

[ $(docker ps -a | grep Exited | wc -l) -ne 0 ] && docker start $(docker ps -a | grep Exited | cut -d' ' -f1)

it worked fine like in pure linux shell , but then error occured when i try to use expect to "send" the command

error info

i dont know if expect pre-parse my command or just my command doesn’t follow its syntax rules.
thanks in advanced if you know how to fix this problem

#!/bin/bash
while read ip pass
do
                {
                /usr/bin/expect <<-END
                spawn ssh [email protected]$ip
                expect {
                "yes/no" { send "yesr";exp_continue }
                "password:" { send "$passr" }
                }
                expect "#"
                send "[ $(docker ps -a | grep Exited | wc -l) -ne 0 ] && docker start $(docker ps -a | grep Exited | cut -d' ' -f1)"
                expect eof
                END
                }&

done<apps_ip.txt

Source: Docker Questions

LEAVE A COMMENT