Can anyone please help me create a bash command to automate a telnet session?
- telnet into session and tee the output.
- input E.
- input B.
- input enter key in a loop until "End of file" is tee'd into file.
- input x
- input x
- input escape command "^]"
- input quit to quit the telnet session
Here is what i've come up with so far but its not working.
{ echo "E"; sleep 0.1; echo "B"; sleep 0.1; } | ( 
    telnet 10.10.10.4 | tee text.txt ) & 
    while sleep 0.1; do
        if grep -q "End of file" text.txt; then break; fi
    done && echo "x" && echo "x" && echo "^]" && echo "quit"
Here is the error:
telnet: Unable to connect to remote host: Connection refused
Trying 10.10.10.4...
[1]  + broken pipe  { echo "E"; sleep 0.2; echo "B"; sleep 0.2; } | 
       done         ( telnet 10.10.10.4 | tee text.txt; )
 
    