Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

df nice output format in emails

Tags:

linux

shell

I sent emails with space usage information.

df -Ph | mailx -s "disk usage" [email protected]

But when I read an email it looks like this:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3          2.0G  372M  1.6G  20% /
tmpfs           32G   12G   20G  38% /dev/shm
/dev/sda1         248M   28M  208M  12% /boot
/dev/mapper/sys-home  4.0G  308M  3.6G   8% /home
/dev/mapper/sys-tmp   2.0G  3.7M  1.9G   1% /tmp
/dev/mapper/sys-rcv   247G  130G  114G  54% /flash_recovery_area
/dev/mapper/sys-usr   4.0G  2.6G  1.4G  66% /usr
/dev/mapper/sys-var   2.0G  291M  1.6G  16% /var
/dev/mapper/orcl-u01  493G  331G  162G  68% /u01
/dev/mapper/orcl-ora  640G  588G   53G  92% /oradata
/dev/sdc1       916G  602G  268G  70% /mnt/backup
/dev/sdb2       516G  241G  250G  50% /oradata/ods

Any ideas, how can I preformat it order to align the column in the table?

I want it prettily formatted:

Filesystem             Size  Used Avail Use% Mounted on
/dev/sda3               2.0G  372M  1.6G  20% /
tmpfs                    32G   12G   20G  38% /dev/shm
/dev/sda1               248M   28M  208M  12% /boot
/dev/mapper/sys-home    4.0G  308M  3.6G   8% /home
/dev/mapper/sys-tmp     2.0G  3.7M  1.9G   1% /tmp
/dev/mapper/sys-rcv     247G  130G  114G  54% /flash_recovery_area
/dev/mapper/sys-usr     4.0G  2.6G  1.4G  66% /usr
/dev/mapper/sys-var     2.0G  291M  1.6G  16% /var
/dev/mapper/orcl-u01    493G  331G  162G  68% /u01
/dev/mapper/orcl-ora    640G  588G   53G  92% /oradata
/dev/sdc1               916G  602G  268G  70% /mnt/backup
/dev/sdb2               516G  241G  250G  50% /oradata/ods
like image 809
Sergii Shevchyk Avatar asked May 18 '12 09:05

Sergii Shevchyk


2 Answers

Try column -t

df -Ph | column -t
like image 189
raittes Avatar answered Oct 28 '22 16:10

raittes


Hooray for perl:

df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; '

might do vaguely what you want. (The numbers are the column widths, negative means left-justified.)

like image 41
Ulrich Schwarz Avatar answered Oct 28 '22 17:10

Ulrich Schwarz