ssh自动登录工具
来源:程序员人生 发布时间:2015-01-24 09:09:18 阅读次数:2983次
博客主页:http://blog.csdn.net/minna_d
脚本实现:
1.根据key选择机房
2.根据key选择机房所对应的机器名
#!/bin/bash
declare -a machine
declare -i lines
declare -a cns
files=`ls /root/.ssh/ | grep "^cn"`
lines=1
for oneline in $files
do
cns["lines"]=${oneline}
lines=$(($lines+1))
done
for key in ${!cns[*]}
do
echo $key ${cns[$key]}
done
declare -i result=1
until [ $result -eq 0 ]
do
read -p "please input file_key: " cn_key
cn_value=${cns["$cn_key"]}
echo "cn_key: $cn_key"
echo "cn_value: $cn_value"
if [ "x" = "x$cn_value" ];then
result=1
else
result=0
fi
done
lines=1
while read oneline
do
var_arr=($oneline)
machine["$lines"]=${var_arr[0]}
lines=$(($lines+1))
done < "/root/.ssh/$cn_value"
for key in ${!machine[*]}
do
echo $key ${machine[$key]}
done
result=1
until [ $result -eq 0 ]
do
read -p "please input key: " login_key
login_value=${machine["$login_key"]}
echo "login_key : $login_key"
echo "login_value : $login_value"
if [ "x" = "x$login_value" ];then
result=1
else
result=0
fi
done
echo $result
echo "login_key : " $login_key "value:" ${machine[$login_key]}
ssh ${machine[$login_key]}
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠