Telnet

Hi,

Need some help on exiting the telnet session from the script.

#!/bin/ksh
telnet <ip>

it would print some text and
it would ask for a username and pwd.

I jus need to capture the text and i need to come out of the telnet session.

is it possible without expect ?

I think you can use nc netcat instead of telnet

example

nc 192.168.1.1 23 < commands > output

i tried nc commands...bad luck nc commands are not supported from my server :frowning:

---------- Post updated at 06:23 AM ---------- Previous update was at 05:57 AM ----------

i tried this and it works fine but is it possible i can store the output in a variable ?

user=aaa
passwd=bbb
host=ip
   (
       sleep 2
       echo "$user";   sleep 2
       echo "$passwd"; sleep 2
    ) | telnet "$host"
info=$((sleep 2 ;echo "$user"; sleep 2 ; echo "$passwd"; sleep 2) | telnet "$host")
echo "$info"

This works with my cisco switch

Everything is fine but is there a way to suppress this part of the output ?

"Connection closed by foreign host."

Try redirecting 2>/dev/null

if i redirect the whole output goes to /dev/null :frowning: