README
monitorFolders.bsh Installation Run a monitor The Answer
unix bash

Overview

I found myself with a run away disk space problem on my dev centos machine, where something I couldn't locate was filling up the disk, so I figured I needed a script to at least find out which folder was being filled.

The first point of call was to find any oversized files using an alias I set up as bigfiles...

bash ::  bigfiles alias
alias bigfiles='find / -xdev -type f -size +100M -print | xargs ls -lh | sort -k5,5 -h -r'

this helps finding individual culprit big files, but if the problem is lots of small files being created then I need bigfolders to find oversized folders (i.e. those with big-files, or lots of files summing up to a problem)...

bash ::  bigfolders alias
alias bigfolders='du -h / 2>/dev/null | sort -rh | head -50'

This then gives me clues to find the problem folder.

Another more labour intensive search can be done using a busier looping script as follows.

monitorFolders.bsh

This bash(4.2) centos linux script is designed to collect folder sizes and poll those folders looking for disk changes, reporting on them as they go.

It must be said - this is not the fastest - maybe due to my bash environment unable to use associative arrays (bash 4.2 isn't capable), so the script needed to store the information in a list that then needed to be scanned each time. (Note, this is hardcoded to the /run folder off of root - primarily designed to expect this to not be the problem mount that is running out of space).

The difference between this script and a df -k or du -sh /xxxx (or du -h --max-depth=1 /xxxx | sort -rh) would be that the script pinpoints which folders are changing size (whereas du would mark the parents of folders as changed as well).

Installation

Copy the script into your desired script folder

Run a monitor

Run the monitor using the command

bash ::  Run command
$ monitorFolders.bsh /var 30       (monitors the folder /var every 30 seconds)

Sat 30 Sep 15:09:38 BST 2023
   Filesystem                           Size  Used Avail Use% Mounted on
   devtmpfs                             1.5G     0  1.5G   0% /dev
   tmpfs                                1.5G     0  1.5G   0% /dev/shm
   tmpfs                                1.5G  172M  1.4G  12% /run
   tmpfs                                1.5G     0  1.5G   0% /sys/fs/cgroup
   /dev/mapper/centos_centos7--vm-root   61G   61G   20K  96% /
   /dev/sda1                           1014M  402M  613M  40% /boot
   tmpfs                                303M   12K  303M   1% /run/user/42
   tmpfs                                303M     0  303M   0% /run/user/0

Checking 60310 folders...
.................................................................................................................................................................................................................................250
.................................................................................................................................................................................................................................500
.................................................................................................................................................................................................................................750
.................................................................................................................................................................................................................................1000
.................................................................................................................................................................................................................................1250
......................................................................................
Directory [/sys/devices/platform/Fixed]... has changed from 36K to 40K (+ 4096 bytes)

.
Directory [/sys/devices/platform/Fixed]... has changed from 36K to 40K (+ 4096 bytes)

.
Directory [/sys/devices/platform/Fixed]... has changed from 36K to 84K

.........................................................................................................................................1500
.................................................................................................................................................................................................................................1750




warningNote, only use this when you are desperate as it will be demanding on the resources

The Answer

So I was running an opencv.js process from php and this was creating large numbers of files in the /procs folder. Restarting apache/linux seems to automatically clean this up.

square

About

License

Latest Release

Version 1.02024-05-08