天天看点

批量修改外网密码

批量修改外网密码

一.安装expect软件 yum install -y expect.这个方便用mkpasswd命令产生随机密码,比如:

mkpasswd  -l 30 -c 3表示长度为30,使用3钟不同的字符

二.建立ip_list.txt文件.在里面设置远程的ip地址,前提是原来已经建立了ssh信任关系。

三.使用以下脚本

#!/bin/bash

#change password with root

#author rolling raw

for ip in `cat /root/ip_list.txt`

do

        tmp_pwd=`mkpasswd -l 30 -c 3`

        r_pwd=`echo ${ip}_${tmp_pwd}`

        echo "${ip}_${tmp_pwd}" > r_pwd.txt

#create password

if [ $? = 0 ];then

        ssh $ip passwd root --stdin < r_pwd.txt

        echo -e "$(date "+%y-%m-%d %h:%m:%s") \t ${r_pwd} \t" >>r_server.log

        else

        echo -e "$(date "+%y-%m-%d %h:%m:%s") \t ${ip} r_pwd.txt is create fail \t please check again! \t" >>m_pass.log

fi

if [ $? = 0 ]; then

        echo -e "$(date "+%y-%m-%d %h:%m:%s") \t the ${ip} passwd is modified ok \t">>m_pass.log

        echo -e "$(date "+%y-%m-%d %h:%m:%s") \t the ${ip} passwd is modified fail \t please check! \t">>m_pass.log

done

直接运行,就可以修改远程服务器的密码了哈。

继续阅读