生产实践:
批量检测远程主机是否能ssh登陆(已提前做好互信),实用小脚本
学习技巧:
while循环 ssh登陆
脚本内容:
#!/bin/bash ############################################################ # $Name: ssh-ck.sh # $Version: v1.0 # $Function: check ssh connect to a remote server # $Author: Zhihe An # $organization: chegva.com # $Create Date: 2017-09-28 ############################################################ #不在控制台输出,输出至文件 Usage: ./ssh-ck.sh > ssh-ck.log 2>&1 while read line; do echo -e "$line \c" && ssh $line -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no "date" #echo -e "$i \c" && ssh $i -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no "date" > /dev/null 2>&1 #if [ $? = 0 ];then # echo $line >> ssh_yes.txt #else # echo $line >> ssh_no.txt #fi done < ../file/host.err
◎查看效果