echo open x.x.x.x
echo "sh run | s pim "
echo 'sh run | i hostname'
echo "sh ip int br | i Loopback"
echo "sh inv | i SN"
) | telnet
Above is the simple telnet program.
I'll try to explain the problem.
Here the echo command is used to pass the commands to router console and not to print the text. So whenever i use redirection for particular line in this program, it redirects the command itself and not the output which router will give.