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.
- #=========== Autotelnet. sh ==========================
- #! /Bin/bash
- Tmptty = 'tty '# obtain the current tty Value
- Tmptty = 'basename $ tmptty '# Remove the absolute path of tty
- Tmpname = 'whoam' # obtain the username of the currently executed Program
- Ip = "10.22.33.44" # target host address
- 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 !!
- # Press ctrl and press v. Do not press ctrl, and then press shift and m.
- Inp2 = "ABC ^ M" # host password, note that ^ M is required
- Inp3 = "ls ^ M" # other commands after entry can be replaced by none or ls commands. Note that ^ M is required.
- Inp4 = "pwd ^ M" # command 4, same as above
- #--------------------------
- Inininputfile = in # It is used to import the file pipeline. Do not change it. This value does not matter.
- Outoutputfile = out. log # final exported file
- Rm-fr $ inputfile
- Rm-fr $ outputfile
- Mknod $ inputfile p
- Touch $ outputfile
-
- # File description 7 for out and 8 for in uses 7 as the input pipeline and 8 as the input
- Exec 7 <> $ outputfile
- Exec 8 <> $ inputfile
-
- Telnet $ ip <& 8> & 7 &
-
- Sleep 2; echo $ inp1 >>$ inputfile
- Sleep 2; echo $ inp2 >>$ inputfile
- Sleep 2; echo $ inp3 >>$ inputfile
- # UNIX automatic logon to telnet settings. If there are no other commands, this line and the next line can be removed.
- Sleep 2; echo $ inp4 >>$ inputfile
-
- Tail-f $ outputfile & force any input/output to be displayed on the screen
-
- While true # normally, it has already entered the target host. You can enter any command, and all input and output will be recorded.
- Do
- Read str
- If [[$ str = "quit" | $ str = "exit"]
- Then echo $ str >>$ inputfile exit
- Else echo $ str >>$ inputfile
- Fi
- Done
-
- # UNIX automatically logs on to telnet and exits to automatically kill related processes
- Ps-ef | greptelnet | grep-v grep | grep-v telnetd | grep $ tmptty | grep $ tmpname | awk '{print "kill-9", $2}' | sh
- Ps-ef | grep tail | grep-v grep | grep-v telnetd | grep $ tmptty | grep $ tmpname | awk '{print "kill-9 ", $2} '| sh