批量更改用户口令
--------prochapawd.sh---------
#!/usr/bin/expect
set timeout 5
set ipaddress [lindex $argv 0]
set username [lindex $argv 1]
set newpassword [lindex $argv 2]
spawn ssh -l root $ipaddress
expect "*#*" {send "hostname\r"}
expect "*#*" {send "passwd $username\r"}
expect "*assword: " {send "$newpassword\r"}
#AIX,this
#expect "again:" {send "$newpassword\r"}
#Linux,UNIX,this
expect "*assword: " {send "$newpassword\r"}
expect "*#*" {send "exit\r"}
expect eof
--------prochapawdexecute.sh---------
#!/bin/bash
echo -n "Enter the user whose password you want to change: "
read user
echo -n "Enter the user's new password: "
read newpassword
if [ -n "$newpassword" ] && [ -n "$user" ]; then
echo "Passwd $user will be executed."
else
echo "The password you enter is null."
exit 1
fi
for ip in $(cat iplist);
do {
ssh ${ip} "id $user"
if [ $? -eq 0 ]; then
/usr/bin/expect prochapawd.sh $ip $user $newpassword
else
continue
fi
}
done
exit 0
浙公网安备 33010602011771号