Bash 脚本删除超过 5 天的目录?

Bash 脚本删除超过 5 天的目录?
#!/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)) ]

相关内容