0

I have an existing working shell script which will send an alert if the space exceeds 85% and but I have a new requirement where if the file size exceeds 85% then the older .csv files(location: /home/STAFF/ssk/Files) which are less than last 3 days should be deleted and I have to schedule this in a crontab. If possible please help me as I am new to Linux in appending that new condition in the existing script.

Below is the existing script.

sample.sh:

 #!/bin/bash
CURRENT=$(df /home/STAFF/ppal007/Files | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=85  
if [ "$CURRENT" -gt "$THRESHOLD" ] ; 
then     
  mail -s 'Disk Space Alert' abc@abc.com << EOF     
Your free space is critically low in the location df /home/STAFF/ssk/Files. Used: $CURRENT% 
EOF 
fi
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • add a find command with mtime or atime or ctime parameters to set that example : `find path/ -ctime +90 -name "*.gz" -exec rm {} \;` will delete files over 90 days in path – francois P Sep 07 '20 at 10:25
  • As an aside, your complex `grep | awk | sed` can be reduced to `awk '/\// { gsub(/%/, ""); print $5 }'`; see also http://www.iki.fi/era/unix/award.html#grep – tripleee Sep 07 '20 at 10:26
  • Pretty small disk if 85% is critical. – tripleee Sep 07 '20 at 10:28

0 Answers0