您的位置:首页 > 运维架构 > Shell

CentOS 6.7编写Shell脚本实现简单跳板机功能

2015-11-28 07:33 796 查看
1、分发密钥(使用普通用户)

ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
ssh-copy-id -i  .ssh/id_dsa.pub 172.16.1.7
ssh-copy-id -i  .ssh/id_dsa.pub 172.16.1.8
2、编写脚本

[root@m01 profile.d]# cat /server/scripts/tiaoban.sh
#!bin/sh
function trapper(){
trap '' INT QUIT TSTP TERM HUB
}
function menu(){
cat <<-EOF
==============Host List==============
1-172.16.1.7/24
2-172.16.1.8/24
0-Exit system
=====================================
EOF
}
function host(){
case "$1" in
1)
ssh $USER@172.16.1.7
;;
2)
ssh $USER@172.16.1.8
;;
0)
exit 0
esac
}
function main(){
while true
do
trapper
clear
menu
read -p "Pls input your choice:" num
host $num
done
}
main
[root@m01 profile.d]# cat /etc/profile.d/tiaoban.sh
[ $UID -ne 0 ] && \
. /server/scripts/tiaoban.sh
3、用普通用户登录跳板机测试,效果图如下:



本文出自 “万越天的架构师之路” 博客,请务必保留此出处http://wanyuetian.blog.51cto.com/3984643/1717659
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: