Script to monitor server total file amount and send e-mails
If you are using an usual hosting or VPS you probably have limit of about 1 mln or eg. 0,5 mln of files (iNODEs). It’s crucial to monitor amount of files especially if you have a lot of aplications generating cache or session files. Hosting providers not always has such monitoring systems, so when you reach the limit hosting will be automaticly blocked and in most cases you cant even login to your admin panel if it’s on the same virtual account.
I wrote short script to count files on your server, check if its exceeds limit and eventualy sends e-mail with warning.
Put it as eg. count_files.sh as low directory as possible eg. “/” for VPS or in /home/username/ directory for standard hosting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#!/bin/bash echo "$(tput setaf 4)$(tput setab 7)STARTING FILE AMOUNT VERIFICATION$(tput sgr 0)" MAXCOUNT=900000 #90% of files limit COUNT="`find ./ -type f | wc -l`" echo "$(tput setaf 4)$(tput setab 7)Amount of files on the server: $COUNT$(tput sgr 0)" while true; do if [ $MAXCOUNT -gt $COUNT ]; then echo "$(tput setaf 2)$(tput bold)FILES AMOUNT = OK$(tput sgr 0)" exit else echo "$(tput setaf 1)$(tput bold)$(tput setab 7)AMOUNT OF FILES IS MORE THAN 90%!$(tput sgr 0)" echo "$(tput setaf 1)$(tput bold)$(tput setab 7)Sending e-mail Alert...$(tput sgr 0)" #Send message mail -s "FILES LIMIT ON SERVER XYZ" "your@email.com" <<< "There are more than 900k files of 1 mln files limit on the server XYZ" exit fi done |