#!/usr/bin/expect -f
log_file exp.log
set timeout -1
set ipaddr [lrange $argv 0 0]
#while {1} {
for {set i 1} {$i<4} {incr i} {
spawn ssh $ipaddr
expect {
"*password:" break
"to host" {sleep 2};
sleep 3
}
}
send "123456\r"
expect "]#"
send "cd /etc/ssh\r"
send "cp sshd_config sshd_config.`date +%F-%T`.bak\r"
send "sed -i /^ListenAddress.*$/d sshd_config\r"
send "echo ListenAddress `/sbin/ifconfig eth0|awk '/inet /{print \$2}'|awk -F: '{print \$2}'` >> sshd_config\r"
send "service sshd restart\r"
send "exit\r"
interact
do.sh
#!/bin/sh
for ip in `cat ip.lst`
do
./ssh.exp $ip > /dev/null 2>&1
done
cat exp.log | grep host | awk '{print $5}'|sort|uniq >> errorip
echo "以下IP无法修改";cat errorip
阅读(1175) | 评论(0) | 转发(0) |