---脚本目的
输入用户名,检测是否已经配置免密登录
---使用方式
1. 把要检测的IP写入当前目录的iplist.txt
2. 执行脚本,按照提示输入要检测的用户名,脚本执行完后会把连接失败的结果写入当前目录的tmp_error_connect.txt文件内
---脚本内容
#!/bin/sh
read -p "请输入连接用户名:" INPUT_USERNAME
cat /dev/null > tmp_error_connect.txt
function getConnection()
{
ssh -o ConnectTimeout=2 -o PasswordAuthentication=no -o NumberOfPasswordPrompts=0 -o StrictHostKeyChecking=no $1@$2 "pwd" &>/dev/null
if [ $? = 0 ];then
echo -e "$2 connection success" >> /dev/null
continue
else
echo -e "$2 connection error" >> tmp_error_connect.txt
fi
}
echo "===================正在执行脚本==================="
for ip in `cat iplist.txt`
do
echo "$ip check finished"
getConnection $INPUT_USERNAME $ip
done
echo "连接失败的IP保存在当前目录的tmp_error_connect.txt文件内"
echo "===================脚本执行完毕==================="