首页 > 其他 > 详细

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

时间:2015-11-12 11:40:58      阅读:316      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!