Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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?