![5일보다 오래된 디렉터리를 삭제하는 Bash 스크립트가 필요합니까? [폐쇄]](https://linux55.com/image/9552/5%EC%9D%BC%EB%B3%B4%EB%8B%A4%20%EC%98%A4%EB%9E%98%EB%90%9C%20%EB%94%94%EB%A0%89%ED%84%B0%EB%A6%AC%EB%A5%BC%20%EC%82%AD%EC%A0%9C%ED%95%98%EB%8A%94%20Bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EA%B0%80%20%ED%95%84%EC%9A%94%ED%95%A9%EB%8B%88%EA%B9%8C%3F%20%5B%ED%8F%90%EC%87%84%5D.png)
#!/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)) ]