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