telnet shell script to automatically log in and execute commands

Telnet achieved by automatic login shell script, and sends commands to achieve telent telnet login performed after the corresponding command at the distal end.

#!/bin/sh

user="admin"
pass="admin"
ip="192.168.128.81"

{
        sleep 1
        echo "$user";     // 登录用户名
        sleep 1
        echo "$pass";     // 登录密码
        //发送对应命令给telnet,循环查看日志信息
        for i in $(seq 1 10)
        do
            sleep 10
            echo "cat /tmp/server.log"
            echo "cat /tmp/server.log > log.txt"
        done

}|telnet $ip

The script can not capture command execution result, only the delay control by the next command, the command for less time-consuming, may lead to reach the intended purpose. If you need to capture and judge the results of the command can expect to use tool.

Guess you like

Origin blog.csdn.net/lisemi/article/details/91952172