标签:
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
标签:
原文地址:http://www.cnblogs.com/yuzhaoxin/p/4958129.html