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.txt
script error
[root@centseven ~]# ./directconnect
spawn echo -e > Report_2017.txt
extra characters after close-quote
while executing
"spawn 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 expect
set timeout 5
spawn echo -e > Report_2017.txt
spawn sh -c "ssh IPaddress "./bin/show_info.py | grep total -A2 | grep -v ^+ | grep -v ^- | sed 's/total.*//g'" > Report_2017.txt"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "12345\r"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "12345\r"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "12345\r"
expect "Password:"
send "54321\r"
interact