how's it going, everything alright? I need to build a script that controls the space of a particular FS which has several directories. On the other hand, it will be necessary to send an email indicating the percentage of occupancy of each Directory and within that FS, on the total occupancy indicating what percentage of the total space each directory occupies. What I am particularly in need of is how I can perform those calculations.
For example, I detail the name of the FS and what each directory occupies
FS : /archivos (5T)
Contenido: /archivos/test/ (1T)
Contenido: /archivos/garbage/ (10 Megas)
Contenido: /archivos/log/ (2T)
Contenido: /archivos/solaris/ (5 kilobytes)
lo que necesitaria es que me muestre algo asi
/archivos -> Ocupoa 5Teras, ocupado 90%
/archivos/test/ (1T), ocupa el 20% del FS /archivos
/archivos/garbage/ (10 Megas), ocupa el 1% del FS /archivos
/archivos/log/ (2T), ocupa el 30% del FS /archivos
/archivos/solaris/ (5 kilobytes), ocupa el 1% del FS /archivos
How can I get that data and calculate the percentage as I need it?
This must be in bash
Your query is not trivial (in fact I would put a price on it) and requires some effort from the labor of a specialized engineer. But I will still try to answer your post just to polish my skills.
What is needed is to process line by line, string by string, practice multiple extractions with regular expressions, standardize formats, operate with common units, then create a template for the result:
sizes.txt
If you put the following content in the file :Running the program you get:
If you think this is a lot of code for a single file, you can separate the functions and call them with
source
at startup.Here are a few unit tests with the suite
bats
:And running them we have:
major update
Believe:
bats
,This is the repository: Repository
This is the small CI/CD pipeline: CI/CD Pipeline
An example of how the tiny DAG passes the stages:
And from the job as a result: