码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-11-12 11:42:17      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/yuzhaoxin/p/4958129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!