- --------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
来源: http://www.bubuko.com/infodetail-3304965.html