(1)case 语法

case "变量" in
模式1) 命令序列1 ;;
模式2) 命令序列2 ;;
模式3) 命令序列3 ;;
*) 无匹配后命令序列
esac

(2)多系统配置yum源

#!/bin/bash
cat << EOF
1.install Centos5 yum repo
2.install Centos6 yum repo
3.install Centos7 yum repo
EOF
clear_cache() {
yum clean all
yum makecache
}
[ -d /etc/yum.repos.d/bak/ ] || mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/ &>/dev/null
read -p "please input a number ,eg 1|2|3 ...." num
case "$num" in
1)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
clear_cache
;;
2)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
clear_cache
;;
3)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
clear_cache
;;
*)
echo "error number!"
esac

(3)删除用户

#!/bin/bash
#case 判断删除用户
read -p "please input username:" user
id $user &>/dev/null
if [ $? -ne 0 ];then
echo "no such user:$user!"
exit 1
fi
read -p "Are you sure?[y|n]: " action
case "$action" in
y|Y|yes|YES)
userdel -r $user
echo "$user is deleted"
;;
*)
echo "error"
esac

(4)模拟jumpserver

#!/bin/bash
trap "" HUP INT OUIT TSTP
web01=192.168.111.201
web02=192.168.111.202
clear
while true
do
cat <<-EOF
+-----------------------------------+
| jumpserver |
| 1)connect---web01 |
| 2)connect---web02 |
| 3)out |
+-----------------------------------+
EOF
echo -en "\e[1;32mplease input a number: \e[0m"
read num
case "$num" in
1)
ssh $web01
;;
2)
ssh $web02
;;
3)
break
;;
*)
echo "error"
esac
done
trap :运行脚本的时候无法使用crtl+c退出脚本
clear 每次登陆到后端服务器退出之后清屏
cat :打印菜单
echo -en "\e[1;32mplease input a number: \e[0m" :提示用户输入的时候打印颜色,-n表示下面的read用户输入不换行
,密钥登录:ssh-keygen:生成跳板机的公钥和私钥 ssh-copy-id 把跳板机的公钥发送给后端服务器
客户端登录到跳板机上每次启动这个脚本需要把脚本放入到~/.bashrc文件下面,脚本需要给执行权限

(5)系统工具箱

#!/bin/bash
#system_toolbox
menu() { cat <<-EOF
+==========================================+
| h.help |
| f.disk partition |
| d.filesystem mount |
| m.memory |
| u.system load |
| q.exit |
+==========================================+
EOF
}
menu
trap "" HUP INT OUIT TSTP
clear
while true
do
menu
echo -en "please enter the options you need:"
read options
case "$options" in
h) clear;menu ;;
f) df -Th ;;
d) fdisk -l ;;
m) free -m ;;
u) upload ;;
q) break ;;
"") ;;
*) echo -e "\e[1;32merror options \e[0m"
esac
done
echo -e "\e[1;32mfinish...... \e[0m"

(5)安装php

#!/bin/bash
menu() {
echo "##############################"
echo -e "\t1 php5.6"
echo -e "\t2 php6.6"
echo -e "\t3 quit"
echo "##############################"
}
. /server/scripts/php.sh
install_php56() {
php56
}
install_php66() {
php66
}
menu
while true
do
echo -ne "version[1-2]:"
read version
case "$version" in
1) install_php56 ;;
2) install_php66 ;;
3) break ;;
"") ;;
*) echo "error"
esac
done

php.sh

#!/bin/bash
php56() {
echo -e "\e[1;31minstall php5.6 is success\e[0m"
}
php66() {
echo -e "\e[1;33minstall php6.6 is suceess\e[0m"
}

总结:把安装php的各种版本一个文件,文件里面是函数安装php各种版本的函数,然后在入口文件使用. /server/scripts/php.sh加载这个文件,在定义函数调用文件中的函数功能即可

最新文章

  1. Beginning Scala study note(1) Geting Started with Scala
  2. SQL Server Column Store Indeses
  3. [Head First设计模式]生活中学设计模式——组合模式
  4. “面向对象&quot;和&quot;面向过程&quot;到底有什么区别?
  5. 【英语】Bingo口语笔记(8) - 爆破音的发音技巧
  6. Ajax获得站点文件内容实例
  7. 泛型Dictionary的用法详解
  8. IOS 播放音频流媒体
  9. baidu地图的一个拾取坐标系统
  10. 双卡双待支持双电池 夏新N808深度评测_夏新手机评测-泡泡网
  11. android编译自己 内置的jar做法
  12. Chapter 1 Securing Your Server and Network(1):选择SQL Server业务经理
  13. I帧/P帧/B帧---术语解释
  14. php垃圾回收
  15. bzoj 3576[Hnoi2014]江南乐 sg函数+分块预处理
  16. 【算法】Bert预训练源码阅读
  17. 小程序如何获取code
  18. 朱晔和你聊Spring系列S1E3:Spring咖啡罐里的豆子
  19. Spring.NET依赖注入框架学习--入门
  20. AtCoder Regular Contest 103 E Tr/ee

热门文章

  1. Win10 1803安装Ubuntu1804子系统
  2. 基于Thinkphp5+phpQuery 网络爬虫抓取数据接口,统一输出接口数据api
  3. 在delphi中如何解决空格的问题。。。。烦死 了。。。。
  4. java实现数据库连接的工具类
  5. bootstrap-table 增加序号列(支持分页)
  6. jsp电子商务购物车之四 数据库存储篇
  7. 【BZOJ 2744 朋友圈】
  8. 收藏一个漂亮的Flash焦点图切换
  9. POJ2492:A Bug&#39;s Life(种类并查集)
  10. 如何解决DuplicateFileException: Duplicate files copied in APK问题