zoukankan      html  css  js  c++  java
  • Shell应用 之 场景主控脚本实现

    1. 场景脚本

      

    2. 课程

      2.1 Shell 典型应用 之 主控脚本实现

      2.2 Shell 典型应用 之 系统信息 及 系统状态分析

      2.3 Shell 典型应用 之 nginx 和 mysql应用状态分析

      2.4 Shell 典型用用 之 应用日志分析

    3. VIM 编辑器设置(未完成)

      3.1 高亮设置:  

        临时设置:用vim进入文件后 :syntax  off 即关闭高亮,:syntax  on 即打开高亮

        永久设置:修改 /etc /vimrc 中的 syntax 为on即高亮,为off即关闭高亮

        按用户更改:进入用户家目录,新建 .vimrc 文件,并添加 syntax on

      3.2 显示行号  :set number

      3.3 自动缩进

      3.4 自动加入文件头

    4. 场景脚本结构

      

    5. Shell 脚本 之 echo 高亮显示

      echo  -e  终端颜色 + 显示内容 + 结束后的颜色

    [root@localhost ~]# echo -e "e[1;32m Wayne say Hi~ e[1;0m"
     Wayne say Hi~ 
    [root@localhost ~]# echo -e "e[1;31m"" Wayne say Hi~"$(tput sgr0)
     Wayne say Hi~
    

    6. Shell 中的关联数组

      普通数组:只能使用整数作为数组索引

      关联数组:可以使用字符串作为数组索引

      申明关联数组变量:# declare  -A  ass_array1

      数组名[索引] = 变量值:# ass_array1[index1]=pear

    7. 场景主控脚本实现

    #!/bin/bash
    
    resettem=$(tput sgr0)
    declare -A ssharray
    i=1
    numbers=""
    
    for script_file in `ls -I "monitor_man.sh" ./`
    do
            echo -e 'e[1;34m' "The script:" ${i} '==>' ${resettem} ${script_file}
            ssharray[$i]=${script_file}
            # echo ${ssharray[$i]}
            numbers="${numbers}${i}, "
            i=$((i+1))
    done
    
    a=$((i-1))
    #echo $a
    
    while true
    do
            read -p "input a number [${numbers}]:" execshell
            if [[ ! ${execshell} =~ ^[1-$a]+ ]];then
                    echo "invalid input"
            else
                    /bin/sh ./${ssharray[$execshell]}
                    #echo ${execshell}
            fi
    done
    
    ~                                                                                  
    ~                                                                                  
    ~                                                                                                                                                                  
    "monitor_man.sh" 30L, 515C
    

    效果图:

      

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    网上怎么赚钱?如何利用CPA赚钱?
    在农村养殖什么赚钱?要做好哪些预防工作?
    计算机组成的基本硬件设备
    JAVA回溯法求0-1背包
    TensorFlow学习笔记之批归一化:tf.layers.batch_normalization()函数
    数据库连接池的大小值设定,不能随意设置太大的值
    N皇后问题
    19个强大、有趣、又好玩的 Linux 命令!
    JAVA马的遍历
  • 原文地址:https://www.cnblogs.com/wnzhong/p/6392160.html
Copyright © 2011-2022 走看看