批量更改用户口令

Posted donggongdechen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量更改用户口令相关的知识,希望对你有一定的参考价值。

--------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
"}
expect "*#*"                {send "passwd $username
"}
expect "*assword: "         {send "$newpassword
"}
#AIX,this
#expect "again:"             {send "$newpassword
"}
#Linux,UNIX,this
expect "*assword: "         {send "$newpassword
"} 
expect "*#*"                {send "exit
"}

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

以上是关于批量更改用户口令的主要内容,如果未能解决你的问题,请参考以下文章

linux系统账号管理与配置!

更改用 C# 编写的 tts 程序的输出设备在 Windows 10 中不起作用

编写代码片段的更简洁的方法

如何从选项卡片段中的 AsyncTask Resftful WS 加载批量数据

Android:将“ViewPager”动画从片段更改为片段

有没有更聪明的方法将布局绑定到片段?