Telnet inside shell script

How to run telnet inside a shell script and execute commands on a remote server?

I did not expect to install on my Solaris machine for security reasons. I also do not have the perl module installed net::telnet.

So using pending and perl, how can I do this?

I tried the following but did not work.

#!/usr/bin/sh
telnet 172.16.69.116 <<!
user
password
ls
exit
!

When I execute it, this is what I get:

> cat tel.sh
telnet 172.16.69.116 <<EOF
xxxxxx
xxxxxxxxx
ls
exit
EOF
> tel.sh
Trying 172.16.69.116...
Connected to 172.16.69.116.
Escape character is '^]'.
Connection to 172.16.69.116 closed by foreign host.
> 
+5
source share
2 answers

Some of your teams may be dropped. You can achieve finer control using regular script constructs, and then send the necessary commands through the pipe using echo. Group the list of commands to make one "session": -

{
sleep 5
echo user
sleep 3
echo password
sleep 3
echo ls
sleep 5
echo exit
} | telnet 172.16.65.209
+11
source

... , , , SSL- - , .

, script, , , , , , , , , escape- (^]) .

-1

All Articles