linux通过shell脚本实现ssh交互式自动化
/usr/bin/expect <<-EOF#开始用expcet执行标志EOF#结束标志expect {} #是expect要实现交互的命令集
# ssh root@10.10.22.38
"*yes/*"
"*password:" { send "$passwd\r" } #如上如果遇到返回值 *代表无限字符,后面是password:则执行 send发送字符串 \r回车
expect "*]*" #等待出现]执行下一条命令
send "df -h\r"#执行命令并回车。
登录后复制
#!/bin/bash
passwd="admin"
/usr/bin/expect <<-EOF set timeout 50 spawn telnet 0 expect { "Login*" { send "admin\r"} } expect { "*assword:" { send "$passwd\r" } } expect { "*admin>" {send "security enable protocol-detect\r"}
}
expect {
"*admin>" {send "security set port-abnormal detect 2\r"}
}
expect {
"*admin>" {send "security show protocol-detect status\r"}
}
expect {
"*admin>" {send "security show port-abnormal-detect level\r"}
}
expect {
"*admin>" {send "exit\r"}
}
EOF
http://blog.itpub.net/69955379/viewspace-2909342/
页:
[1]