Shell – Ignore changing size of “df -h” while using diff

diff()disk-usageshell-script

I'm trying to compare the file systems among many other basic services, before and after server reboot to check if any mismatches are present.

I'm currently saving the data to a file and am comparing using diff command

As there are many servers this is not being effective, as this is also checking the difference in the FS size too; as can be seen from below.

diff -rs ./prechecks/file ./postchecks/file
10c10
< udev                                                                  7.8G  164K  7.8G   1% /dev
---
> udev                                                                  7.8G  156K  7.8G   1% /dev
13c13
< /dev/mapper/vg01-lvopt_IBM                                            9.9G  8.2G  1.2G  88% /opt/IBM
---
> /dev/mapper/vg01-lvopt_IBM                                            9.9G  8.3G  1.2G  88% /opt/IBM
18,19c18,19

I've tried If we can use ignore option, but I couldn't get through the logic.

I want to check if we can overcome this.? This is taking toll as I have to deal with many hundreds of servers each time.

Else, Is there a way to ignore the tabs – Size; Used; Avail; Use%; in the output of df -h as seen below which will eliminate the check in the first place.

Filesystem                                      Size  Used Avail Use% Mounted on
/dev/mapper/vg00-lvroot                          20G   16G  4.5G  78% /

Help me solve the challenge. Thanks.!

EDIT1:
df --output=source,fstype,target is my first choice, but I'm unable to do it on another servers
df: unrecognized option '–output=source,fstype,target'
Try `df –help' for more information.
Any other workaround.?

Best Answer

Is there a way to ignore the tabs - Size; Used; Avail; Use%;

The df command output fields are adjustable via --output option:

df -h --output='source'

The above will output only filesystem names list

Filesystem
/dev/mapper/vg00-lvroot

--output[=FIELD_LIST]
use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted.


If some options are unsupported try the following workaround with awk:

df -h | awk '{print $1}'
Related Question