随着数据文件的增长,磁盘可能会满,所以须要监控某文件夹所在磁盘使用状态,当使用率到达70%时发出警报,直接发送邮件到指定邮箱,能够经过autosys调度系统结合shell命令写出以下JIL脚本:shell
/*----------------------adw_uxdw1_monitor----------------------*/ insert_job:adw_uxdw1_monitor job_type:CMD command:/bin/df -kh /adw/dw/appdata | /bin/sed -n '3p' | /bin/awk '{print substr($4,1,length($4)-1)}' | /bin/awk '{if($0>=70) print "exit 1"; else print "exit 0"}' | ksh machine:adw ownner:user@adw peimission: date_conditions:1 days_of_week:all start_times:"03:00,09:00,15:00,21:00" description:"to check disk space usage of directory /adw/dw/appdata" std_out_file:">/adw/dw/appdata/log/adw_uxdw1_monitor.out" std_err_file:">/adw/dw/appdata/log/adw_uxdw1_monitor.err" alarm_if_fail:0 /*----------------------adw_uxdw1_alter_mail----------------------*/ insert_job:adw_uxdw1_alter_mail job_type:CMD command:/bin/mailx -s "Alert - Disk space usage of directory /adw/dw/appdata is greater than 70% on `date`" shanshan@gmail.com < /dev/null machine:adw ownner:user@adw peimission: date_conditions:0 start_times:e(adw_uxdw1_monitor)=1 description:"send alter eamail if the disk space usage is greater than 70%" std_out_file:">/adw/dw/appdata/log/adw_uxdw1_alter_mail.out" std_err_file:">/adw/dw/appdata/log/adw_uxdw1_alter_mail.err" alarm_if_fail:1
1. df [选项] [文件]app
- 用于显示目前在Linux系统上的文件系统的磁盘使用状况统计,这里针对一个文件夹,会显示该文件夹所在磁盘信息
- -h human-readable用人类可读的方式显示,具体就是好比size是显示468M而不是479156
- -k like --block_size=1K 这里可加可不加
2. sed -hnV-f<script文件> or nl /etc/file | sed 'action'spa
- -n --silent 静静地去掉自动空间,仅显示处理后结果
- '3p' print第三行。这里由于文件名长出字段长度单独占了一行,因此use%在第三行
3. ... | awk '{[pattern] action}' --用法之一code
- print 打印出第四个变量($4从1开始计数,这里由于文件名在上一行,因此第五个字段use%在这里是第四个字符)截取的从第一个到倒数第二个字符的内容。也就是去掉最后一个字符%
- '{}'里面能够用if, else。 exit是一个状态,至关于返回值。
任务完成时经常须要发信通知,这里仅列出发信命令,至于任务完成,这里经过脚本直接记录在文件OK.csv中(完成日,任务简称SRC,任务来源地,行数)这样记录。所以发信命令经过读取该文件完成。
/bin/mailx -s "$${REGION}-REGION: TheDate:bin\cat /usr/staging/OK.csv | grep SRC | awk -F"," '{print }'
"ip
4. mailx -s "email subject" aaa@abc.com < fileit
- 用于发送邮件的命令,-s是subject的意思,通常都要带
- < file 指的是邮件内容为file的内容