Turn from: http://blog.csdn.net/edei2004/article/details/3694021
Many people think that telnet, like passwd and Su, cannot be turned on by pipes and inputs to make it work automatically, but Telnet actually supports input steering. Although, strictly speaking, the shell script does not allow Telnet into the interaction State, But it does allow you to enter the remote system and run the command you wish to exit. This is far more reassuring than using rsh (Remsh,rcmd),
Use the following script to meet your requirements:
(Sleep 1;echo user;sleep 1, echo Passwd;echo yourcmd; sleep 1) |telnet RemoteHost
Where user,passwd,yourcmd,remotehost are replaced by your username, user password, you want to run the command, remote machine name or IP can be. If you want to use a script to enter the interaction state, you can use expect.
If you want to get some of the data by telnet to an IP port, you can use the following command
(sleep 5;) | Telnet IP Port This allows you to print the PORT's output in 5 seconds after telnet to the screen and then exit automatically
EG:
tempvalue= "KEY"
str4= ' (Sleep 1;echo aa;sleep 1; echo 123; sleep 1; Echo tail-f/aa/log/a.log;sleep 1) | te Lnet ${ip} | grep ${tempvalue} '
num4= ' echo ${#str4} '
if [${num4}-eq 0];then
echo ' =:: in A.log file Keyword key not found, please check! "
sheet4= "@NULL
Else
echo" =:: Found keyword key! in a.log file
sheet4= "@OK"
Fi