shell脚本编程进阶while循环和控制
1.配置发邮件的设置
set from=29308620@qq.com set smtp=smtp.qq.com set smtp-auth-user=29308620@qq.com set smtp-auth-password=esvnhbnqocirbicf set smtp-auth=login set ssl-verify=ignore
将上述追加到/etc/mail.rc中
2.配置发邮件的邮箱
#!/bin/bash WARNING=80 while true;do USE=`df | sed -rn '/^\/dev\/sd/s#.* ([0-9]+)%.*#\1#p' |sort -nr|head -n1` if [ $USE -gt $WARNING ];then echo Disk will be full from `hostname -I` | mail -s "disk warning" 791402385@qq.com fi sleep 10 done
3.continue
提前结束当前循环
1:提前结束当前1次循环
2:提前结束当前2次循环
范例:100内奇数相加
4.break
退出当前循环
1:退出当前第一轮循环
2:退出当前第二轮循环