on the remote machine there is one script ./bin/show_info.py which I want to execute and get the output on the local machine, for which i have created a script with expect.If I run the below command it works properly, but when the same in mentioned in the script it gives error. ssh IPaddress ./bin/show_info.py |  grep  total -A2 | grep -v ^+ | grep -v ^-  | sed 's/total.*//g' > Report_2017.txtscript error [root@centseven ~]# ./directconnectspawn echo -e > Report_2017.txtextra characters after close-quote    while executingspawn sh -c ssh IPaddress ./bin/show_info.py | grep total -A2 | grep -v ^+ | grep -v ^- | sed 's/total.*//g' > Report_2017.tx...    (file ./directconnect line 6)file content#!/usr/bin/env expectset timeout 5spawn echo -e > Report_2017.txtspawn sh -c ssh IPaddress ./bin/show_info.py | grep total -A2 | grep -v ^+ | grep -v ^- | sed 's/total.*//g' > Report_2017.txtexpect Enter passphrase for key '/root/.ssh/id_rsa':send 12345\rexpect Enter passphrase for key '/root/.ssh/id_rsa':send 12345\rexpect Enter passphrase for key '/root/.ssh/id_rsa':send 12345\rexpect Password:send 54321\rinteract
expect script giving error
shell script;scripting;expect
The double quotes are a problem in your case in the expect script.spawn sh -c ssh IPaddress ./bin/show_info.py |.. sed 's/total.*//g' > Report_2017.txtJust observe that due to the double quotes ending after IPaddress, the pipe is left exposed.You may want to try this:spawn sh -c ssh IPaddress \./bin/show_info.py |.. sed 's/total.*//g'\ > Report_2017.txt