#!/bin/bash
# 批量确认服务器 ssh 密码
# 默认 root 用户
# Requirements:yum -y install sshpass expect
res="res.txt"
err_res="err_res.txt"
pwds="xxxx@htjj2021 xxxx.root.xxxx xxxx.root.xxx JS@xxxx"
for ip in `cat ip.txt`;
do
flag=0
for pwd in ${pwds}
do
sshpass -p ${pwd} ssh -o StrictHostKeyChecking=no root@${ip} "exit"
# 判断sshpass执行是否成功
if [ $? -eq 0 ];then
# 提示信息,当前正在测试的IP 和密码
echo -e "\n[ Success ] IP=\"${ip}\" password=\"${pwd}\" "
# 将找到的密码保存到文件里
echo "${ip} ansible_ssh_password=${pwd}" >> ${res}
${flag}=1
else
# 提示当前这个密码没有成功
echo "[ Failure ] password=\"${pwd}\""
fi
done
if [ $flag == 0 ];then
echo "${ip}" >> ${err_res}
fi
done