until [ condition ] #当条件不满足的时候才循环<-----------刚好差不多与while相反
do
commanddone
while [ condition ] #当条件满足的时候就继续循环
do command done
case "choice" in
var1 ) command ;; var2 ) command ;; var3 ) command ;; var4 ) command ;; * ) command =================================================================数组
定义三种:a=(var1 var2 "var 3")
[root@dns shell_01]# a=(tom mary roy "wel to upl") [root@dns shell_01]# echo ${a[0]} tom访问数组:
echo ${a[0]}方式2:
a[xx]=value # xx只能是数字,代表数组的元素下标 [root@dns shell_01]# b[1]=tom [root@dns shell_01]# b[3]=mary [root@dns shell_01]# b[5]="hello moto" [root@dns shell_01]# echo ${b[1]} tom [root@dns shell_01]# echo ${b[0]}[root@dns shell_01]# echo ${b[5]}
hello moto方式3:
[root@dns shell_01]# c=([1]=tom [5]=mary [3]=roy)
[root@dns shell_01]# echo ${c[1]} tom [root@dns shell_01]# echo ${c[5]} mary [root@dns shell_01]# echo ${c[3]} roy 获取数组的元素的个数: echo ${#a[*]} 获取数组所有元素: echo ${c[*]} echo ${c[@]}数组的复制
e=(${a[*]})
例子:
记录用户登录的详细信息记录到某个自定义的日志里,要求用到数组,格式时间 用户名 登录来自的主机名或者IP
YY-MM-DD 11:39 root 10.1.1.128 ps w who 例子: 递归判断某个目录下的所有的死链接linkchk /tmp/test
/tmp/test/subdir
递归判断某个目录下的所有文件的权限
========================================
ifconfig eth0 | grep "inet addr" | awk '{print $2}' | awk -F: '{print $2}'
10.1.1.20 awk -F: '{print $1}' /etc/passwd awk -F: '{print $1"-----"$NF}' /etc/passwd 例子: 监控磁盘的使用百分比,如果超过90%就发用警告邮件给本地管理员
监控系统的负载,超过某个指标就发警告邮件给本地管理员
echo "6.8 > 5" | bc
小数运算 [root@dns shell_03]# echo "scale=9; 9.5/4 + 4.6" | bc #scale=9 指定有效位数 6.975000000作业:
编写一个脚本,能够监控本机的ssh,dns,httpd,mail,vsftp等服务的是否启动,把运行结果发送到管理员邮箱里。要求输出结果:
-------------------------- 主机名字 日期时间 -------------------------- 服务名字 : 状态 SSH : YES MAIL : NO <--这只是输出例子 其他省略 --------------------------