验证两台机器已经建立的ssh互信

1.expect方法

  

#!/bin/bash

checkTrust()
{
        expect -c '
        set timeout 2;
        spawn ssh $1 "expr 12345678 + 87654321"
        expect {
                "*yes/no*" {send \003;}
                "*assword*" {send \003;}
                -re "#|$|>" {send exit\r;}
        }
        expect eof;'
}

result=`checkTrust $1 | grep "99999999"`

echo result=$result

 

#./checkTrust.sh 192.168.0.10
result=99999999

#./checkTrust.sh 11.11.11.11
result=

 2.ssh 返回值

ssh 192.168.0.100 -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no "echo a" > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "Trust not exist."
fi

 

posted on 2015-11-12 10:19  BFP  阅读(414)  评论(0编辑  收藏  举报