涉及的shell知识点:
1.exec的使用;2.for和if的使用;3.函数的使用;4.dh -h和awk的使用
2.删除文件和文件夹都是使用rm命令。删除文件夹要加上-rf
3.注意点:(())和 [ ] 中前后都要留空格
关于定时任务:使用crontab来执行脚本即可
第一种方法(例子为:删除指定文件):通过使用exec将脚本内产生的 输出重定向到指定文件中
#!/bin/bash
##***脚本功能:
##*****1.当磁盘使用率高于94%,删除history_file文件下的早期AVL文件
##lxy
exec 1> /home/fwzlgl/script/logs/delete_file_`date "+%Y%m%d"`.log 2> /home/fwzlgl/script/logs/delete_file_`date "+%Y%m%d"`.bad
##通用路径
basic_path=/home/fwzlgl/data/history_file/
##文件日期
file_data_day=`date "+%Y%m%d"`
file_data_month=`date -d "-2month" +"%Y%m"`
##监控磁盘使用率
our_memory=`df -h | awk -F '[ %]+' '/\/$/{print $5}'`
if (( $our_memory>92 ));then
for i in {1..45}
do
##