1753502 Members
4954 Online
108794 Solutions
New Discussion юеВ

Re: verif disk usage

 
iranzo
Frequent Advisor

verif disk usage

Hello,
i look for script to verify disk usage
on linux server,
i start with ' df -H | grep -vE '^Filesystem|tmpfs|cdrom '
but now i want to extract just
pattern with a "%" in line,
like "13%" for example.
Thanks a lot
Bonjour
3 REPLIES 3
Matti_Kurkela
Honored Contributor

Re: verif disk usage

If I understood correctly what you're looking for, you want just the Use% part of each line.
It's the 5th whitespace-separated "word" on the line, so awk can pick it out nicely.

However, some versions of df will add a line feed after the device name if the name is so long it would push the columns out of alignment. To avoid this, add option -P to the df command:

df -PH | grep -vE '^Filesystem|tmpfs|cdrom ' | awk '{ print $5; }'

You can even pick multiple columns, in any order you wish. For example, to output the name of the mount point and its Use% value only:

df -PH | grep -vE '^Filesystem|tmpfs|cdrom ' | awk '{ print $6, $5; }'

MK
MK
Lucifer Megacruel
Valued Contributor

Re: verif disk usage

Hi,

You can also make use of python, use the os module ( i need to search for the exact function), search the python documentation. Then you can generate reports, make a cool ui etc

I prefer python over traditional shell scripts since python scripts tend to be more maintainable. But that's just me!.


--Lucifer
"To Denouce the Evils of Truth and Love. To cause may hem and destruction and necromancy , Lucifer is here"
Wilfred Chau_1
Respected Contributor

Re: verif disk usage

df -HP|awk '{if (NR!=1 && $5 == "13%") print $6 "\t" $5}'

This will output the filesystem and its usage only if the usage is exactly 13%.

Is this something you need?