How to use shell scripts to implement automatic Telnet

Source: Internet
Author: User

Many people think that, like passwd and Su, Telnet cannot work automatically through pipelines and input redirection, but in fact Telnet supports input redirection. although, strictly speaking, shell scripts cannot enable telnet to enter the interactive state, it does enable you to log on to the remote system and exit after running the command you want. 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
Replace user, passwd, yourcmd, and remotehost with your username, user password, command you want to run, remote machine name or IP address. if you want to use the script to enter the interaction status, you can use keep CT.

If you want to obtain part of the data through Telnet the port of an IP address, you can use the following command

(Sleep 5;) | Telnet IP port. In this way, you can print the data output from the port within 5 seconds to the screen after telnet, and then exit automatically.

Eg:
Tempvalue = "key"
Str4 = '(sleep 1; echo AA; sleep 1; echo 123; sleep 1; echo tail-F/AA/log/. log; sleep 1) | Telnet $ {IP} | grep $ {tempvalue }'
Num4 = 'echo $ {# str4 }'
If [$ {num4}-EQ 0]; then
Echo "=: the keyword key is not found in the. Log File. Check the key! "
Sheet4 = "@ null"
Else
Echo "=: the keyword key is found in the. 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.