2019-01-31 leo check disk usage and auto remove old files


#!/bin/bash --login
shopt -s expand_aliases
while :
do
  today=$(date -I -d "3 hours ago"|tr -d "-")
  usage=$(df -h|grep -i vdb1|awk '{print $5}'|cut -d% -f1)
  if [ "$usage" -gt 60 ] ; then
     cd /sdb/dsp-bidder-logs/
     ls -ht|grep -v "$today"|xargs sudo rm -rf
     cd /sdb/dsp-bidder-logs/${today}
     ls -lht|sed -n '30,$p'|awk '{print $NF}'|xargs sudo rm -rf
  else
    echo "disk usage is ${usage}"
  fi
  sleep 900
done

你可能感兴趣的:(2019-01-31 leo check disk usage and auto remove old files)