标签:flag 告警系统需求分析 mtu .sh bin grep lag 定义 监控系统
shell脚本中的函数}
函数必须要放在最前面,function可以省略直接写函数名
[root@akuilinux01 shell]# cat fun1.sh
#!/bin/bash
function inp(){
echo "the first par is $1"
echo "the sedcond par is $2"
echo "the third par is $3"
echo "the scritp name is $0"
echo "the number of par is $#"
}
inp b a 2 3 sjkdj
[root@akuilinux01 shell]# sh fun1.sh
the first par is b
the sedcond par is a
the third par is 2
the scritp name is fun1.sh
the number of par is 5
第一个参数是b,第二个是a,第三个是2,脚本名是fun1.sh,参数个数是5.
[root@akuilinux01 shell]# cat fun1.sh
#!/bin/bash
function inp(){
echo "the first par is $1"
echo "the sedcond 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
[root@akuilinux01 shell]# sh fun1.sh 1 2 3
the first par is 1
the sedcond par is 2
the third par is 3
the scritp name is fun1.sh
the number of par is 3
示列2,第一个参数和第二个参数相加并打印
[root@akuilinux01 shell]# cat fun2.sh
#!/bin/bash
sum(){
s=$[$1+$2]
echo $s
}
sum 1 10
[root@akuilinux01 shell]# sh fun2.sh
11
函数的核心命令推演
[root@akuilinux01 shell]# ifconfig |grep -A1 "ens33"
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.21.128 netmask 255.255.255.0 broadcast 192.168.21.255
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.21.133 netmask 255.255.255.0 broadcast 192.168.21.255
[root@akuilinux01 shell]# ifconfig |grep -A1 "ens33: "
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.21.128 netmask 255.255.255.0 broadcast 192.168.21.255
[root@akuilinux01 shell]# ifconfig |grep -A1 "ens33: "|awk ‘/inet/‘
inet 192.168.21.128 netmask 255.255.255.0 broadcast 192.168.21.255
[root@akuilinux01 shell]# ifconfig |grep -A1 "ens33: "|awk ‘/inet/‘|awk -F ‘ ‘ ‘{print$2}‘
192.168.21.128
[root@akuilinux01 shell]# cat fun3.sh
#!/bin/bash
ip()
{
ifconfig |grep -A1 "$1: "|awk ‘/inet/‘|awk -F ‘ ‘ ‘{print$2}‘
}
while :
do
read -p "Please input the eth name:" eth
n=`ifconfig|grep "$eth"`
if [ -z "$eth" ]
then
echo "你必须输入一个网卡名"
elif [ -z "$n" ]
then
echo "请你输入正确的网卡名"
continue
else
break
fi
done
ip_=`ip $eth`
if [ -z "$ip_" ]
then
echo "$eth:这个网卡没有配置ip"
else
echo "$eth:$ip_"
fi
[root@akuilinux01 shell]# sh fun3.sh
Please input the eth name:
你必须输入一个网卡名
Please input the eth name:dada
请你输入正确的网卡名
Please input the eth name:ens33
ens33:192.168.21.128
[root@akuilinux01 shell]# sh fun3.sh
Please input the eth name:ens37
ens37:这个网卡没有配置ip
[root@akuilinux01 shell]# a=(as b cd)
[root@akuilinux01 shell]# echo ${a[@]}
as b cd
[root@akuilinux01 shell]# echo ${a[*]}
as b cd
[root@akuilinux01 shell]# echo ${a[2]}
cd
[root@akuilinux01 shell]# echo ${a[1]}
b
[root@akuilinux01 shell]# echo ${a[0]}
as
[root@akuilinux01 shell]# echo ${#a[*]}
3
[root@akuilinux01 shell]# a[5]=4
[root@akuilinux01 shell]# echo ${#a[*]}
4
[root@akuilinux01 shell]# echo ${a[*]}
as b cd 4
[root@akuilinux01 shell]# a[1]=2
[root@akuilinux01 shell]# echo ${a[*]}
as 2 cd 4
[root@akuilinux01 shell]# unset a[0]
[root@akuilinux01 shell]# echo ${a[*]}
2 cd 4
[root@akuilinux01 shell]# unset a
[root@akuilinux01 shell]# echo ${a[*]}
[root@akuilinux01 shell]# a=(seq 1 10
)
[root@akuilinux01 shell]# echo ${a[*]}
1 2 3 4 5 6 7 8 9 10
1 2 3
8 9
[root@akuilinux01 shell]# echo ${a[@]/7/5}
1 2 3 4 5 6 5 8 9 10
[root@akuilinux01 shell]# a=(${a[@]/8/3})
[root@akuilinux01 shell]# echo ${a[@]}
1 2 3 4 5 6 7 3 9 10
(主目录 mon)
|
--------------------------------------------------------------------------------------
| | | | |
bin conf shares mail log
[main.sh] [mon.conf] [load.sh 502.sh] [mail.py mail.sh] [mon.log err.log ]
bin下是主程序
conf下是配置文件
shares下是各个监控脚本
mail下是邮件引擎
log下是日志。
shell脚本中的函数,shell中的数组,shell项目-告警系统
标签:flag 告警系统需求分析 mtu .sh bin grep lag 定义 监控系统
原文地址:http://blog.51cto.com/akui2521/2145035