CentOS 6.7编写Shell脚本实现简单跳板机功能,centosshell
CentOS 6.7编写Shell脚本实现简单跳板机功能,centosshell
1、分发密钥(使用普通用户)
ssh-keygen-tdsa-P''-f~/.ssh/id_dsa
ssh-copy-id-i.ssh/id_dsa.pub172.16.1.7
ssh-copy-id-i.ssh/id_dsa.pub172.16.1.8
2、编写脚本
[root@m01profile.d]#cat/server/scripts/tiaoban.sh
#!bin/sh
functiontrapper(){
trap''INTQUITTSTPTERMHUB
}
functionmenu(){
cat<<-EOF
==============HostList==============
1-172.16.1.7/24
2-172.16.1.8/24
0-Exitsystem
=====================================
EOF
}
functionhost(){
case"$1"in
1)
ssh$USER@172.16.1.7
;;
2)
ssh$USER@172.16.1.8
;;
0)
exit0
esac
}
functionmain(){
whiletrue
do
trapper
clear
menu
read-p"Plsinputyourchoice:"num
host$num
done
}
main
[root@m01profile.d]#cat/etc/profile.d/tiaoban.sh
[$UID-ne0]&&
./server/scripts/tiaoban.sh
3、用普通用户登录跳板机测试,效果图如下:
评论暂时关闭