20.16 20.17shell中的函数(上下);20.18 shell中的数组;20.19 告警系统需求分析
2017-09-18 15:42
585 查看
20.16 shell中的函数(上)
函数就是把一段代码整理到了一个小单元中,并给这个小单元起
一个名字,当用到这段代码时直接调用这个小单元的名字即可。
1.
[root@hao-01 ~]# vi fun1.sh
添加内容:
#!/bin/bash
function inp(){
echo "The first par is $1"
echo "The second par is $2"
echo "The third par is $3"
echo "the scritp name is $0"
echo "the number of par is $#"
}
inp $1 $2 $3
2. 执行fun1.sh脚本,后面跟函数:
[root@hao-01 ~]# sh fun1.sh 1
20.17 shell中的函数(下)
1. 加法函数:
[root@hao-01 ~]# vi fun2.sh
添加内容:
#!/bin/bash
sum() {
s=$[$1+$2]
echo $s
}
sum 1 10
2. 执行fun2.sh脚本:
[root@hao-01 ~]# sh -x fun2.sh
1. 输入网卡名字,显示网卡ip:
[root@hao-01 ~]# vi fun3.sh
添加内容:
#!/bin/bash
ip()
{
ifconfig |grep -A1 "$1: "|awk '/inet/ {print $2}'
}
read -p "please input the eth name: " ech
ip $eth
2. 执行fun3.sh脚本:
[root@hao-01 ~]# sh fun3.sh
please input the eth name: ens33
20.18 shell中的数组
1. 定义数组:
[root@hao-01 ~]# a=(1 2 3 4 5)
2. 查看a数组的元素:
[root@hao-01 ~]# echo ${a[*]}
3. 查看数组某个元素的值(数组从0开始值为1):
[root@hao-01 ~]# echo ${a[1]}
4. 获取数组的元素 个数:
[root@hao-01 ~]# echo ${#a[*]}
5. 如果下标不存在则会自动添加一个元素:
[root@hao-01 ~]# a[5]=b
[root@hao-01 ~]# echo ${a[*]}
数组元素赋值(更改替换):
[root@hao-01 ~]# a[5]=bbb
[root@hao-01 ~]# echo ${a[*]}
6. 删除数组元素:
7. 删除(清空)数组值:
[root@hao-01 ~]# unset a
[root@hao-01 ~]# echo ${a[*]}
8. 设定数组:
[root@hao-01 ~]# a=(`seq 1 10`)
[root@hao-01 ~]# echo ${a[*]}
9. 从第1个元素开始,截取出5个数值:
[root@hao-01 ~]# echo ${a[*]:0:5}
从第2个元素开始,截取出5个数值:
[root@hao-01 ~]# echo ${a[*]:1:5}
10. 从倒数第3个元素开始,截取出2个数值:
[root@hao-01 ~]# echo ${a[*]:0-3:2}
11. 截取替换,8元素打印成cc66:
[root@hao-01 ~]# echo ${a[@]/8/cc66}
12. 替换元素值,8元素替换成cc66:
[root@hao-01 ~]# a=(${a[*]/8/cc66})
[root@hao-01 ~]# echo ${a[*]}
替换元素值,cc66元素替换成888:
[root@hao-01 ~]# a=(${a[*]/cc66/888})
[root@hao-01 ~]# echo ${a[*]}
20.19 告警系统需求分析
1. 需求:使用shell定制各种个性化告警工具,但需要统一化管理、规范化管理。
2. 思路:指定一个脚本包,包含主程序、子程序、配置文件、邮件引擎、输出日志等。
3. 主程序:作为整个脚本的入口,是整个系统的命脉。
4. 配置文件:是一个控制中心,用它来开关各个子程序,指定各个相关联的日志文件。
5. 子程序:这个才是真正的监控脚本,用来监控各个指标。
6. 邮件引擎:是由一个python程序来实现,它可以定义发邮件的服务器、发邮件人以及发件人密码
7. 输出日志:整个监控系统要有日志输出。
函数就是把一段代码整理到了一个小单元中,并给这个小单元起
一个名字,当用到这段代码时直接调用这个小单元的名字即可。
1.
[root@hao-01 ~]# vi fun1.sh
添加内容:
#!/bin/bash
function inp(){
echo "The first par is $1"
echo "The second par is $2"
echo "The third par is $3"
echo "the scritp name is $0"
echo "the number of par is $#"
}
inp $1 $2 $3
2. 执行fun1.sh脚本,后面跟函数:
[root@hao-01 ~]# sh fun1.sh 1
20.17 shell中的函数(下)
1. 加法函数:
[root@hao-01 ~]# vi fun2.sh
添加内容:
#!/bin/bash
sum() {
s=$[$1+$2]
echo $s
}
sum 1 10
2. 执行fun2.sh脚本:
[root@hao-01 ~]# sh -x fun2.sh
1. 输入网卡名字,显示网卡ip:
[root@hao-01 ~]# vi fun3.sh
添加内容:
#!/bin/bash
ip()
{
ifconfig |grep -A1 "$1: "|awk '/inet/ {print $2}'
}
read -p "please input the eth name: " ech
ip $eth
2. 执行fun3.sh脚本:
[root@hao-01 ~]# sh fun3.sh
please input the eth name: ens33
20.18 shell中的数组
1. 定义数组:
[root@hao-01 ~]# a=(1 2 3 4 5)
2. 查看a数组的元素:
[root@hao-01 ~]# echo ${a[*]}
3. 查看数组某个元素的值(数组从0开始值为1):
[root@hao-01 ~]# echo ${a[1]}
4. 获取数组的元素 个数:
[root@hao-01 ~]# echo ${#a[*]}
5. 如果下标不存在则会自动添加一个元素:
[root@hao-01 ~]# a[5]=b
[root@hao-01 ~]# echo ${a[*]}
数组元素赋值(更改替换):
[root@hao-01 ~]# a[5]=bbb
[root@hao-01 ~]# echo ${a[*]}
6. 删除数组元素:
7. 删除(清空)数组值:
[root@hao-01 ~]# unset a
[root@hao-01 ~]# echo ${a[*]}
8. 设定数组:
[root@hao-01 ~]# a=(`seq 1 10`)
[root@hao-01 ~]# echo ${a[*]}
9. 从第1个元素开始,截取出5个数值:
[root@hao-01 ~]# echo ${a[*]:0:5}
从第2个元素开始,截取出5个数值:
[root@hao-01 ~]# echo ${a[*]:1:5}
10. 从倒数第3个元素开始,截取出2个数值:
[root@hao-01 ~]# echo ${a[*]:0-3:2}
11. 截取替换,8元素打印成cc66:
[root@hao-01 ~]# echo ${a[@]/8/cc66}
12. 替换元素值,8元素替换成cc66:
[root@hao-01 ~]# a=(${a[*]/8/cc66})
[root@hao-01 ~]# echo ${a[*]}
替换元素值,cc66元素替换成888:
[root@hao-01 ~]# a=(${a[*]/cc66/888})
[root@hao-01 ~]# echo ${a[*]}
20.19 告警系统需求分析
1. 需求:使用shell定制各种个性化告警工具,但需要统一化管理、规范化管理。
2. 思路:指定一个脚本包,包含主程序、子程序、配置文件、邮件引擎、输出日志等。
3. 主程序:作为整个脚本的入口,是整个系统的命脉。
4. 配置文件:是一个控制中心,用它来开关各个子程序,指定各个相关联的日志文件。
5. 子程序:这个才是真正的监控脚本,用来监控各个指标。
6. 邮件引擎:是由一个python程序来实现,它可以定义发邮件的服务器、发邮件人以及发件人密码
7. 输出日志:整个监控系统要有日志输出。
相关文章推荐
- 20.16/20.17 shell中的函数 20.18 shell中的数组20.19 告警系统需求分析
- 20.16/20.17 shell中的函数 20.18 shell中的数组 20.19 告警系统需求
- linux学习第六十六篇:shell中的函数,shell中的数组,告警系统需求分析
- shell中的函数 shell中的数组 告警系统需求分析
- shell中的函数、shell中的数组、告警系统需求分析
- shell中的函数、shell的数组、告警系统需求分析
- 十六周四次课 2018.02.08 shell中的函数、shell中的数组、告警系统需求分析
- 【shell编程】shell中的函数、shell中的数组和告警系统需求分析
- shell中的函数、数组及告警系统需求分析
- shell中的函数,shell中的数组,告警系统需求分析,
- shell中的函数,shell中的数组,告警系统需求分析
- shell中的函数(function)、数组、告警系统分析
- shell中的函数、数组、告警系统分析
- Shell告警系统(需求分析,告警系统主脚本,告警系统配置文件,告警系统监控项目)
- 警告系统需求分析 告警系统配置文件 告警系统监控项目load.sh
- 邮件告警系统需求分析
- 告警系统需求分析 告警系统主脚本 告警系统配置文件 告警系统监控项目
- 疯狂的订餐系统-软件需求分析挑战之旅-2
- 论软件需求分析方法和工具的选用—论文2:企业集团的信息管理系统应用
- 【机房收费系统】上下机分析