码迷,mamicode.com
首页 > 其他好文 > 详细

批量更改用户口令

时间:2019-11-26 19:14:10      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:timeout   pad   who   cat   ipad   null   hostname   ash   password   

--------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

批量更改用户口令

标签:timeout   pad   who   cat   ipad   null   hostname   ash   password   

原文地址:https://www.cnblogs.com/donggongdechen/p/11937353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!