echo "show run"
the above commands gives input to terminal of router and then displays output on terminal. i want the output of this specific command to be redirected to the file. please help me

man bash /Redirecting Output

echo "show run" > filename

Anything similar to this will redirect this text "show run" to the file and not the output of router.

???

show run > file

please be more precise about the context.

what's the router?
what OS?
what shell?
...

(
echo open x.x.x.x
sleep 2
echo "usrname"
sleep 1
echo "pass"
sleep 1
echo "sh run | s pim "
sleep 1
echo 'sh run | i hostname'
sleep 1
echo "sh ip int br | i Loopback"
sleep 1
echo "sh inv | i SN"
sleep 1
echo "logout"
sleep 1
) | 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.

sorry, I don't have experience with telnet.

subshell can be avoided using a list :

{
command1
command2
} | command >file

are all those echo useful? you could use a here-doc

telnet <<EOF >file
open x.x.x.x
sleep 2
usrname
sleep 1
pass 
sleep 1
sh run | s pim 
sleep 1
sh run | i hostname
sleep 1
sh ip int br | i Loopback
sleep 1
sh inv | i SN
sleep 1
logout
sleep 
EOF
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.