因为公司接了一个密码托管的活,有10000多台机器,系统有 openSUSE,SUSE,Ubuntu,centos,Oracle-Linux,
而且什么版本都有,不给root权限,密码已经过期很多,先用expect的方式把过期密码修改完成,在进行托管
#!/bin/bash
#Author:shsnc-****
#Time:2021-5-11
#Name:for_user.sh
#Version:V1.3
#Description:This is a password check script.
>passwd.info
>passwd.error
old_passwd=$1
new_passwd=$2
user=gziaas
# 定义并发
thread=10
fifofile="/tmp/$$.fifo"
mkfifo $fifofile
exec 8<>${fifofile}
rm -f ${fifofile}
for pid in `seq ${thread}`
do
echo >&8
done
# 定义修改函数
function change_passwd_ssh(){
/usr/bin/expect << EOF
set timeout 20
spawn /usr/bin/ssh ${user}@$ip
expect {
"(yes/no)?" {send "yes\r";exp_continue}
"*assword:" {send "${old_passwd}\r";}
}
expect {
"(current) UNIX password:" {send "${old_passwd}\r";}
"Old Password:" {send "${old_passwd}\r";}
}
expect {
"New *assword:" {send "${new_passwd}\r";}
"Retype new password:" {send "$new_passwd\r";}
}
expect {
"Retype new password:" {send "$new_passwd\r";}
}
expect {
"Reenter New Password:" {send "$new_passwd\r";}
"Retype new password:" {send "$new_passwd\r";}
}
send "exit\r"
expect eof
EOF
}
# 脚本主体
for ip in `cat ip_list.txt`
do
read -u 8
{
change_passwd_ssh $1 $2 1>>./passwd.info 2>>./passwd.error
if [ $? -eq 0 ];then
echo "${ip}" >>./successful.ip
else
echo "${ip}" >>./fail.ip
fi
echo >&8
}&
done
wait
exec 8>&-
-----你努力获得的,都是自己的,不容易忘掉。 星辰和大海都需要门票,诗和远方的路费都很贵。来人间一次,努力成为最好的自己。人间值得,未来可期。
标签:fifofile,过期,ip,echo,passwd,expect,普通用户
From: https://www.cnblogs.com/cheyunhua/p/18158116