资源描述:
《Linux Shell 编程一》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、LinuxShell编程一一.变量,数组二.if,while,until,for,case,三.function四.test,[],(()),[[]],``,$()五.
2、,<><<>>,stdinstdoutstderr六.正则脚本示例#!/bin/bash#========================================================================================#RAIDhealthpluginforNagios##Writtenby:Roland#Release:1.0.0#Creationdate:2010-06
3、-10#Revisiondate:2010-06-10#Description:Nagiosplugin(script)tocheckRAIDhealth.#ThisscripthasbeendesignedandwrittenonLinuxSystem.##USAGE:./check_raid_health.sh[-d(raidnum)]##Exemple:./check_raid_stats.sh#./check_raid_stats.sh-draid1###HISTORY:#Release
4、Date
5、Authors
6、Description#--------------+------
7、----------+----------------------+----------------------------------#1.0.0
8、2010-06-10
9、Roland
10、Createthescript#-----------------------------------------------------------------------------------------#NOTICE:#-----------------------------------------------------------------------------------------#
11、YoushouldhavetherootPermissions,Youcanusesudotorealize.#-----------------------------------------------------------------------------------------#Nagiosreturncodes#定义nagios返回的状态变量STATE_OK=0STATE_WARNING=1STATE_CRITICAL=2STATE_UNKNOWN=3#Pathstocommandsusedinthisscript.Thesemayhavetobemodifiedtomat
12、chyoursystemsetup.#定义关键的核心命令MegaCli路径。#MEAGCLI=/root/MegaCli-AdpAllInfo-aALL
13、egrep"Degrade
14、FailedDisks
15、Offline"
16、egrep-v"No
17、Yes"#Pluginparametersvalueifnotdefine#定义默认的检测RAIDCHECK_RAID="raid1"#Pluginvariabledescription#插件定义此插件脚本的描述信息PROGNAME=$(basename$0)RELEASE="Revision1.0.0"AUTHOR="(c)2010Roland
18、(Rolandqu@gmail.com)"#Functionspluginusage#插件的使用方法函数print_release(){echo"$RELEASE$AUTHOR"}print_usage(){echo""echo"$PROGNAME$RELEASE-RAIDhealthcheckscriptforNagios"echo""echo"Usage:check_raid_health.sh-draid1"echo""echo"-dtheRAID(raidnum)"echo"-vchecktheversion"echo"-hShowthispage"echo""echo"Usag
19、e:$PROGNAME"echo"Usage:$PROGNAME--help"echo""exit0}print_help(){print_usageecho""echo"Thispluginwillcheckdiskhealth"echo""exit0}#Parseparameters#传递参数while[$#-gt0]docase"$1"in-h
20、--help)print_helpexit$STATE_OK;;-v
21、--vers