How to implement automatic Telnet with shell script

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.