#!/bin/bashbash
for ip in `cat iplist.txt`ssh
doide
pwd=`mkpasswd -l 12 -s 0 -C 0`spa
grep -q $ip /root/pwd.log&&passwd=$(grep $ip /root/pwd.log|cut -d: -f2)||passwd=123456ip
expect -c "it
spawn ssh root@$ip passwdclass
expect {sed
\"*yes/no*\" { send \"yes\r\";exp_continue }grep
\"*password*\" { send \"$passwd\r\"; }密碼
}
expect {
\"*New password:\" { send \"$pwd\r\";exp_continue }
\"Retype new password:\" { send \"$pwd\r\";exp_continue }
\"*#\" { send \"exit\r\"; }
}
"
[[ -f /root/pwd.log ]]&&sed -i "/^$ip/d" /root/pwd.log
echo "$ip:$pwd" >>/root/pwd.log
done
其中passwd=123456是初始密碼
新密碼放在/root/pwd.log裏面
ip列表放在腳本目錄下的iplist.txt裏面