#!/bin/bash
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>>/var/log/folderpurge.log 2>&1
date
###########################
# Self Explanatory printf #
###########################
if [[ ! $EUID == 0 ]]; then
echo "This script must be run as root."
exit 1
fi
########################################################################
# Check the current local(nix) folder size before initiating the purge #
########################################################################
if [ -e /home/s3user/extractedISOs/ ] && [ $(du -hsm /home/s3user/extractedISOs | awk '{print $1}' -gt $((1024*50)) ]
then
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "| The extractedISOs folder exists and it is greater than 50GB |"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "++++++++++++++++++++"
echo "| INITIATING PURGE |"
echo "++++++++++++++++++++"
#foldpurg=$(find /home/s3user/extractedISOs/* -type d -ctime +5 -exec rm -rf {} \;);
foldpurg=$(find /home/s3user/extractedISOs/* -type d -ctime +5 | xargs rm -rf);
else
exit
fi
exit 0
**Error at line 20 and 35?**
답변1
내가 실수하지 않는 한 du 문의 닫는 괄호가 누락된 것입니다.
[ $(du -hsm /home/s3user/extractedISOs | awk '{print $1}' -gt $((1024*50)) ]
다음이 작동합니다.
[ $(du -hsm /home/s3user/extractedISOs | awk '{print $1}' ) -gt $((1024*50)) ]