1、创建shell脚本的文件存放路径
mkdir -p /data/shelltest/
vi test.sh
2、 创建shell 脚本
#!/bin/bash
##***脚本功能:
##*****1.当磁盘使用率高于90%,删除history_file文件下的早期AVL文件
echo "-----函数开始执行-----"
##通用路径
basic_path=/encoder4editing/notebooks/img_tmp/
##监控磁盘使用率
our_memory=`df -h | awk -F '[ %]+' '/\/$/{print $5}'`
##某目录当前的大小
img_tmpsize=`du --max-depth 1 -lh /encoder4editing/notebooks/img_tmp`
echo '当前'$basic_path'大小为'$img_tmpsize
if (( $our_memory>55 ));then
##获取待删除文件完整路径
file_path=$basic_path
echo '对'$file_path'下的10分钟之前的【jpg】文件执行删除操作,磁盘使用率为'$our_memory'%'
##判断是否有该目录,有则进入,无则提示无
if [ ! -d $file_path ];then
echo '不存在'$file_path
else
echo '进入到'$file_path'执行删除文件夹操作'
## 某目录下前10分钟以前的jpg文件
## find /encoder4editing/notebooks/img_tmp/ -type f -mmin +10 -name "*.jpg" | xargs rm -rf
fi
else
echo '磁盘使用率为'$our_memory'%,未达到90%,不执行任何操作'
fi
echo "-----函数执行完毕-----"
3、执行命令查看结果
./test.sh