bdf command output normally looks scattered especially when VG names are long. It will be difficult to grep out proper pattern out of such output. Also, its not convenient to share this output over email/document when extra lines breaks exists.
In such scenarios, we need to have proper formatted output of bdf. Also sometimes we require output with all its column left aligned.
Solution :
To remove line breaks from bdf output and get single row per entry output
See below normal bdf output. Note that last 2 mount points has two line entry since filesystem column has long entry.
# bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 2097152 737416 1349304 35% /
/dev/vg00/lvol1 1048576 206160 835928 20% /stand
/dev/vg00/lvol8 8388608 5475640 2902568 65% /var
/dev/vg00/lvol7 8388608 4655256 3713000 56% /usr
/dev/vg00/lvol4 2097152 1052368 1036888 50% /tmp
/dev/vg00/lvol6 8388608 6675168 1700112 80% /opt
/dev/vg00/lvol5 524288 49360 471256 9% /home
testserver01:/data
50574008 4541896 43463104 9% /data
/dev/vgdata/lvol1
918421504 591931608 306084338 66% /datastore
Now with inline awk we format the output to have one entry per row. Check below command output.
# bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");print line$0} else {print}}'
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 2097152 737408 1349312 35% /
/dev/vg00/lvol1 1048576 206160 835928 20% /stand
/dev/vg00/lvol8 8388608 5475640 2902568 65% /var
/dev/vg00/lvol7 8388608 4655256 3713000 56% /usr
/dev/vg00/lvol4 2097152 1052368 1036880 50% /tmp
/dev/vg00/lvol6 8388608 6675168 1700112 80% /opt
/dev/vg00/lvol5 524288 49360 471256 9% /home
testserver01:/data 50574008 4541896 43463104 9% /data
/dev/vgdata/lvol1 918421504 591931608 306084338 66% /datastore
To get left aligned bdf output
In above output, columns are not aligned properly. We can even do that with below argument.
# bdf | awk '/\//{printf("%-30s%-10s%-10s%-10s%-5s%-10s\n",$1,$2,$3,$4,$5,$6)}'
/dev/vg00/lvol3 2097152 737408 1349312 35% /
/dev/vg00/lvol1 1048576 206160 835928 20% /stand
/dev/vg00/lvol8 8388608 5472792 2905392 65% /var
/dev/vg00/lvol7 8388608 4655256 3713000 56% /usr
/dev/vg00/lvol4 2097152 1052368 1036888 50% /tmp
/dev/vg00/lvol6 8388608 6675168 1700112 80% /opt
/dev/vg00/lvol5 524288 49360 471256 9% /home
Please make a note that this awk wont remove any line breaks from output. So one can combine (with pipe |) both awk to get left aligned output with line breaks removed.
Left aligned output with line breaks removed!
# bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");print line$0} else {print}}' |awk '/\//{printf("%-30s%-10s%-10s%-10s%-5s%-10s\n",$1,$2,$3,$4,$5,$6)}'
/dev/vg00/lvol3 2097152 737408 1349312 35% /
/dev/vg00/lvol1 1048576 206160 835928 20% /stand
/dev/vg00/lvol8 8388608 5481008 2897240 65% /var
/dev/vg00/lvol7 8388608 4655256 3713000 56% /usr
/dev/vg00/lvol4 2097152 1052368 1036888 50% /tmp
/dev/vg00/lvol6 8388608 6675168 1700112 80% /opt
/dev/vg00/lvol5 524288 49360 471256 9% /home
testserver01:/data 50574008 4541896 43463104 9% /data
/dev/vgdata/lvol1 918421504 591931608 306084338 66% /datastore
No comments
Post a Comment
Any thoughts?