UNIX Automatic Logon telnet code setting solution (1)

Source: Internet
Author: User

UNIX systems are used in many enterprises. This is a complex application. Here we will explain how to set up UNIX Automatic Logon telnet. In order to help you understand this part, we have collected some materials and sorted them out. Here we will share with you. Http://www.linuxeden.com/forum/t138058.html ). This is a good example. I will analyze it below.

 
 
  1. #=========== Autotelnet. sh ==========================
  2. #! /Bin/bash
  3. Tmptty = 'tty '# obtain the current tty Value
  4. Tmptty = 'basename $ tmptty '# Remove the absolute path of tty
  5. Tmpname = 'whoam' # obtain the username of the currently executed Program
  6. Ip = "10.22.33.44" # target host address
  7. Inp1 = "ABC ^ M" # host user name. Note that ^ M must be reinstalled in the UNIX Automatic Logon telnet mode and entered in the following method for use !!
  8. # Press ctrl and press v. Do not press ctrl, and then press shift and m.
  9. Inp2 = "ABC ^ M" # host password, note that ^ M is required
  10. Inp3 = "ls ^ M" # other commands after entry can be replaced by none or ls commands. Note that ^ M is required.
  11. Inp4 = "pwd ^ M" # command 4, same as above
  12. #--------------------------
  13. Inininputfile = in # It is used to import the file pipeline. Do not change it. This value does not matter.
  14. Outoutputfile = out. log # final exported file
  15. Rm-fr $ inputfile
  16. Rm-fr $ outputfile
  17. Mknod $ inputfile p
  18. Touch $ outputfile
  19.  
  20. # File description 7 for out and 8 for in uses 7 as the input pipeline and 8 as the input
  21. Exec 7 <> $ outputfile
  22. Exec 8 <> $ inputfile
  23.  
  24. Telnet $ ip <& 8> & 7 &
  25.  
  26. Sleep 2; echo $ inp1 >>$ inputfile
  27. Sleep 2; echo $ inp2 >>$ inputfile
  28. Sleep 2; echo $ inp3 >>$ inputfile
  29. # UNIX automatic logon to telnet settings. If there are no other commands, this line and the next line can be removed.
  30. Sleep 2; echo $ inp4 >>$ inputfile
  31.  
  32. Tail-f $ outputfile & force any input/output to be displayed on the screen
  33.  
  34. While true # normally, it has already entered the target host. You can enter any command, and all input and output will be recorded.
  35. Do
  36. Read str
  37. If [[$ str = "quit" | $ str = "exit"]
  38. Then echo $ str >>$ inputfile exit
  39. Else echo $ str >>$ inputfile
  40. Fi
  41. Done
  42.  
  43. # UNIX automatically logs on to telnet and exits to automatically kill related processes
  44. Ps-ef | greptelnet | grep-v grep | grep-v telnetd | grep $ tmptty | grep $ tmpname | awk '{print "kill-9", $2}' | sh
  45. Ps-ef | grep tail | grep-v grep | grep-v telnetd | grep $ tmptty | grep $ tmpname | awk '{print "kill-9 ", $2} '| sh


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.