Bash脚本可以根据天数

时间:2018-05-11 06:58:45

标签: bash

我正忙着写一个shell脚本;我被卡住了我正在尝试检查目录中是否存在特定大小的漏洞;当它到达那里;我想删除所述目录中的文件;基于+ mtime。 话虽如此;我是bash的新手,我被困在算术部分。这是代码:     #!/斌/庆典

# Usage: cleanup_old_logs <folder> <days>
# Removes all log files in the directory older than a certain number of days

ALERT=90
FOLDER=~ NAME_TO_FOLDER_T)_MONITOR - removed for example
SIZE=$(df -k $FOLDER | tail -1 | awk '{print $4}')
N_DAYS=2

# check if the available space is smaller than < 90%
if (($SIZE -gt $ALERT)); then
# find all files under $FOLDER and delete them
echo "Deleting files in $FOLDER older than $N_DAYS days"
# Remove
find $FOLDER/* -maxdepth 1 -mtime +$N_DAYS  -type f|wc -l ## -exec rm -rf {} \;
fi

这是我的错误:

line 13: ((: 86% -gt 90%: division by 0 (error token is "90%")

1 个答案:

答案 0 :(得分:0)

df用于检查文件系统。手册页:

  

df显示包含每个文件名参数的文件系统上可用的磁盘空间量。

您需要du

du -s /home/lohit/bin | cut -f1

结果

43567213

相关问题