(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加载这个文件,在定义函数调用文件中的函数功能即可

(7)case语句的更多相关文章

  1. sh4.case语句

    case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构.case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case语句格式如下: ...

  2. 为什么说在使用多条件判断时switch case语句比if语句效率高?

    在学习JavaScript中的if控制语句和switch控制语句的时候,提到了使用多条件判断时switch case语句比if语句效率高,但是身为小白的我并没有在代码中看出有什么不同.去度娘找了半个小 ...

  3. 在 case 语句中使用字符串-转

    http://www.cnblogs.com/del/archive/2008/07/08/1237856.html 非常遗憾 Delphi 的 case 语句不支持字符串, 但我觉得这也可能是基于效 ...

  4. Oracle IF & CASE语句

    IF语句主要有以下三种基本形式: 一. IF-THEN语句 IF CONDITION THEN           STATEMENT 1;           ...           STATE ...

  5. Mysql之case语句(附带实例)

    这段时间,做项目做累了,好不容易有点个人的学习时间,利用这个小时,总结一下,最近做统计的时候常用的case语句吧. 结构:case  when… then …end 1.判断的同时改变其值 eg:   ...

  6. case语句

    case语句是多分支选择语句,if语句只有两个分支可供选择,而实际问题中常常需要用到多分支选择结构.例如,学生成绩分类(90分以上为A,--):人口统计分类(按年龄分为老.中.青.少.幼)等.当然这些 ...

  7. shell script 学习笔记-----if,for,while,case语句

    1.if内的判断条件为逻辑运算: 2.if内的判断条件为目录是否存在,文件是否存在,下图先检验目录/home/monster是否存在,然后再检测/home/monster中的file.txt文件是否存 ...

  8. (二)shell中case语句、程序传参、while

    2.2.6.1.case语句(1)shell中的case语句和C语言中的switch case语句作用一样,格式有差异(2)shell中的case语句天生没有break,也不需要break,和C语言中 ...

  9. [shell基础]——if/for/while/until/case 语句

    for语句 do echo $loop done ` do echo $loop done for loop in `ls /tmp` do echo $loop done while语句 while ...

  10. java中的Switch case语句

    java中的Switch case 语句 在Switch语句中有4个关键字:switch,case break,default. 在switch(变量),变量只能是整型或者字符型,程序先读出这个变量的 ...

随机推荐

  1. springboot ueditor 使用心得

    1.将ueditor引入项目中会发现,图片不能上传,返回值意思是因配置文件错误,导致图片无法上传 默认情况是使用jsp初始配置文件,这就需要项目支持jsp解析 在maven中引入 <!--添加对 ...

  2. servlet 接受和回复向服务器对客户端发起得请求

    servlet 接受和回复向服务器对客户端发起得请求

  3. P3032 [USACO11NOV]二进制数独Binary Sudoku

    题目描述 Farmer John's cows like to play an interesting variant of the popular game of "Sudoku" ...

  4. Intel QuickAssist Technology and OpenSSL – Benchmarks and Setup Tips

    Intel QuickAssist Technology and OpenSSL – Benchmarks and Setup Tips 来源:https://www.servethehome.com ...

  5. Codeforces 821E Okabe and El Psy Kongroo(矩阵快速幂)

    E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. 【题解】AHOI2009中国象棋

    还记得第一次看见这题的时候好像还是联赛前后的事了,那时感觉这题好强……其实现在看来蛮简单的,分类讨论一下即可.题意非常的简单:每一行,每一列都不能超过两个棋子.考虑我们的dp,如果一行一行转移的话行上 ...

  7. 【题解】NOI2014购票

    实际上是一个不完美算法……cogs上面A不掉(爆栈啦).感谢机房大佬PPY的指点,现在也写出来供大家参考参考,理解起来应该是比较简单的一种. 我们首先get出斜率优化方程: \(dp[v] = dis ...

  8. Walk 解题报告

    Walk 题目描述 给定一棵 \(n\) 个节点的树,每条边的长度为 \(1\),同时有一个权值\(w\).定义一条路径的权值为路径上所有边的权值的最大公约数.现在对于任意 \(i \in [1,n] ...

  9. Codeforces Round #328 (Div. 2) A

    A. PawnChess time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  10. bzoj 4004 [JLOI2015]装备购买 拟阵+线性基

    [JLOI2015]装备购买 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 1820  Solved: 547[Submit][Status][Dis ...