Tambien, eso.
Devices__ReportDiskParts.sh
#!/bin/sh
#23456789+123456789+123456789+123456789+123456789+123456789+123456789+123456789+123456789+123456789+
####################################################################################################
###
### $Id: Devices__ReportDiskParts.sh,v 1.7 2021/02/20 02:43:37 root Exp root $
###
### Script to report all partitions that detected by the system.
###
####################################################################################################
TMP=/tmp/`basename $0 ".sh" `.tmp
doFSTAB=0
while [ $# -gt 0 ]
do
case $1 in
"--fstab" ) doFSTAB=1 ; break ;;
"--disk" ) lsblk -l -p --output-all | awk '/[/]dev[/]sd[a-z][0-9]/ { print $0 }' | sort --key=3 | awk '{ printf("%s\n\n", $0 ) ; }' ; exit 0 ;;
"--pairs" ) lsblk -p -P --output-all | awk '/[/]dev[/]sd[a-z][0-9]/ { print $0 }' | sort --key=3 | awk '{ printf("%s\n\n", $0 ) ; }' ; exit 0 ;;
"--raw" ) lsblk -l -p --output-all | sort --key=3 | awk '{ printf("%s\n\n", $0 ) ; }' ; exit 0 ;;
* ) echo "\n\t Invalid parameter '$1' used on command line. Only options allowed: [ --raw | --disk | --fstab ]\n Bye!\n" ; exit 1 ;;
esac
done
if [ -z "${MROOT}" ]
then
MROOT="/site" ; export MROOT
fi
pROOT=`df / | grep '/dev/' | awk '{ print $1 }' `
dROOT=`echo ${pROOT} | cut -c1-8 `
# If not terminal redirect comments to stderr.
if [ -t 1 ] ; then echo "\n\t NOTE: Expected mount point parent for all partitions not on root device => '$MROOT' ..." ; fi
#if [ ! -t 1 ] ; then echo "\n\t NOTE: Expected mount point parent for all partitions not on root device => '$MROOT' ..." >&2 ; fi
###
### All available parameters for lsblk (based on lsblk from util-linux 2.31.1)
###
### In sort order reported by --output-all
###
#1 NAME
# KNAME
# MAJ:MIN
#2 FSTYPE
#5 MOUNTPOINT
#ALT3 LABEL
#4 UUID
# PARTTYPE
#3 PARTLABEL
# PARTUUID
# PARTFLAGS
# RA
# RO
# RM
# HOTPLUG
# MODEL
# SERIAL
#6 SIZE
# STATE
# OWNER
# GROUP
# MODE
# ALIGNMENT
# MIN-IO
# OPT-IO
# PHY-SEC
# LOG-SEC
# ROTA
# SCHED
# RQ-SIZE
# TYPE
# DISC-ALN
# DISC-GRAN
# DISC-MAX
# DISC-ZERO
# WSAME
# WWN
# RAND
# PKNAME
# HCTL
# TRAN
#7 SUBSYSTEMS
# REV
# VENDOR
# ZONED
#lsblk -l -p -o NAME,FSTYPE,PARTLABEL,UUID,SIZE,MOUNTPOINT,SUBSYSTEMS | grep -v 'GRUB' | awk '/[/]dev[/]sd[a-z][0-9]/ { print $0 }' | sort --key=3 > ${TMP}.lsblk
#cat ${TMP}.lsblk
#cat ${TMP}.lsblk | awk '{ print NF }'
lsblk -P -p -o NAME,FSTYPE,PARTLABEL,UUID,SIZE,MOUNTPOINT,SUBSYSTEMS | grep -v 'GRUB' | awk '/[/]dev[/]sd[a-z][0-9]/ { print $0 }' | sort --key=3 > ${TMP}.lsblk.PAIRS
#cat ${TMP}.lsblk.PAIRS
while read line
do
eval echo '${line}' | tr ' ' "\n" |
{ fTYPE=""
while read data
do
eval echo '${data}' | awk -F'"' -v ftype="${fTYPE}" '{
split($1, vars, "=" ) ;
Fname=vars[1] ;
# Fval=vars[2] ;
Fval=$2 ;
if( Fval == "" ){
Fval="null" ;
} ;
printf("%s ", Fval) ;
# printf("%s|%s ", Fname, Fval) ;
}'
# case ${data} in
# FSTYPE* ) fTYPE="USB" ;;
# * ) ;;
# esac
done
}
echo ""
done <${TMP}.lsblk.PAIRS >${TMP}.lsblk
#cat ${TMP}.lsblk
#cat ${TMP}.lsblk | awk '{ print NF }'
## WD 4 TB My Book
#----------------------------------------------------------------------------------------------------------------------
#/dev/sdb1 on /site/My Book type exfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,iocharset=utf8,namecase=0,errors=remount-ro,uhelper=udisks2)
### 1,4,9,7,5,18
#----------------------------------------------------------------------------------------------------------------------
### /dev/sdb1 exfat My Book Not_Mounted /My
#/dev/sdb1 /dev/sdb1 /dev/sdb1 8:17 3.7T 3.7T exfat 6M 0% /site/My Book My Book 40FA-E56B fc843c51-1aec-4aab-8676-9043c9e59d0d atari ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 My Book 4c1ee663-135c-4809-a61e-f38ec52d80a7 128 0 0 1 3.7T root disk brw-rw---- 0 4096 0 4096 512 1 mq-deadline 2 part 0 4K 4G 0 0B 1 /dev/sdb block:scsi:usb:pci none
#----------------------------------------------------------------------------------------------------------------------
### /dev/sde3 ext4 DB002_F1 1b4157be-79cd-472b-96d9-a4cabacaffe1 Not_Mounted /site/DB002_F1
#/dev/sde3 /dev/sde3 /dev/sde3 8:67 ext4 DB002_F1 1b4157be-79cd-472b-96d9-a4cabacaffe1 9a3649a5-cbbb-4f1b-ae0b-f3c0d9cdec21 dos c12a7328-f81f-11d2-ba4b-00a0c93ec93b DB002_F1 a9b2eda8-ec21-4999-b1f6-eab36ce3bf75 128 0 0 0 279.4G root disk brw-rw---- 0 4096 0 4096 512 1 mq-deadline 64 part 0 0B 0B 0 0B 0x50014ee263b2c636 1 /dev/sde block:scsi:pci none
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
### **** ERROR **** Not handling 'My Passport' condition correctly
###
### Reporting as follows:
### /dev/sde1 ntfs My null Mounted 1.8T /media/ericthered/My
#----------------------------------------------------------------------------------------------------------------------
if [ ${doFSTAB} -eq 0 ]
then
if [ -t 1 ] ; then echo "\n\t ALL recognized DISK partitions:\n" ; fi
#if [ ! -t 1 ] ; then echo "\n\t ALL recognized DISK partitions:\n" >&2 ; fi
cat ${TMP}.lsblk | awk -v othrPath=${MROOT} -v dROOT="${dROOT}" '{
if ( $6 == "null" ){
if ( $2 == "swap" ){
printf("%-12s %-8s %-10s %-38s %-13s %-30s %s\n", $1, $2, $3, $4, "Not_Enabled", "[SWAP_OFFLINE]", $7 ) ;
}else{
if ( index($1,dROOT) == 0 ){
thatPath=sprintf("%s/%s", othrPath, $3 ) ;
printf("%-12s %-8s %-10s %-38s %-13s %-30s %s\n", $1, $2, $3, $4, "Not_Mounted", thatPath, $7 ) ;
}else{
thatPath=sprintf("/%s", $3 ) ;
printf("%-12s %-8s %-10s %-38s %-13s %-30s %s\n", $1, $2, $3, $4, "Not_Mounted", thatPath, $7 ) ;
} ;
} ;
}else{
if ( $2 == "swap" ){
printf("%-12s %-8s %-10s %-38s %-13s %-30s %s\n", $1, $2, $3, $4, "Enabled", $6, $7 ) ;
}else{
printf("%-12s %-8s %-10s %-38s %-13s %-30s %s\n", $1, $2, $3, $4, "Mounted", $6, $7 ) ;
} ;
} ;
}'
else
if [ -t 1 ] ; then echo "\n\t ALL recognized DISK partitions reported in format required to update '/etc/fstab':\n" ; fi
#if [ ! -t 1 ] ; then echo "\n\t ALL recognized DISK partitions reported in format required to update '/etc/fstab':\n" >&2 ; fi
#/dev/sdd1 ext4 DB002_F1 0aa50783-954b-4024-99c0-77a2a54a05c2 300G /site/DB002_F1
#UUID=f56b6086-229d-4c17-8a5b-e68de1a4e73d / ext4 errors=remount-ro 0 1
#UUID=7e9a663e-ff1d-4730-8544-c37519056b6f /DB001_F2 ext4 nosuid,nodev,nofail,errors=remount-ro 0 2
#UUID=c37e53cd-5882-401c-8ba3-172531a082e9 none swap sw,pri=3 0 0
###
### FUTURES: USB options rw,suid,umask=0000,uid=1000,gid=1000
###
cat ${TMP}.lsblk | awk -v othrPath=${MROOT} -v pROOT="${pROOT}" -v dROOT="${dROOT}" '{
if( index( $0, "usb" ) != 0 ){
usbPlug="USB_EXTERNAL" ;
}else{
usbPlug="INTERNAL" ;
} ;
if ( $6 == "null" ){
if ( $2 == "swap" ){
if ( $1 == pROOT ) {
perms="sw,pri=1" ;
seq=1 ;
}else{
perms="sw,pri=2" ;
seq=2 ;
} ;
if( $4 == "null" ){
printf("### %s ### No value for UUID. No file system on this partition.\n\n", $3 ) ;
}else{
printf("# %-12s %-8s %-10s %-38s %-13s %s %s\n", $1, $2, $3, $4, $5, "[SWAP]", usbPlug ) ;
printf("UUID=%s \t%s \t%s \t%s \t%s \t%s\n\n", $4, "none", $2, perms, "0", seq ) ;
} ;
}else{
if ( $1 == pROOT ) {
perms="defaults" ;
seq=0 ;
}else{
#perms="nosuid,nodev,nofail,defaults" ;
if( usbPlug == "USB_EXTERNAL" ){
perms="defaults,nofail,noauto" ;
}else{
perms="defaults,nofail" ;
} ;
if ( $1 ~ dROOT ) { seq=1 ; }else{ seq=2 ; } ;
} ;
if( $4 == "null" ){
printf("### %s ### No value for UUID. No file system on this partition.\n\n", $3 ) ;
}else{
if ( index($1,dROOT) == 0 ){
printf("# %-12s %-8s %-10s %-38s %-13s %s/%s %s\n", $1, $2, $3, $4, $5, othrPath, $3, usbPlug ) ;
printf("UUID=%s \t%s/%s \t%s \t%s \t%s \t%s\n\n", $4, othrPath, $3, $2, perms, "0", seq ) ;
}else{
printf("# %-12s %-8s %-10s %-38s %-13s /%s %s\n", $1, $2, $3, $4, $5, $3, usbPlug ) ;
printf("UUID=%s \t/%s \t%s \t%s \t%s \t%s\n\n", $4, $3, $2, perms, "0", seq ) ;
} ;
} ;
} ;
}else{
if ( $2 == "swap" ){
if ( $1 == pROOT ) {
perms="sw,pri=1" ;
seq=1 ;
}else{
perms="sw,pri=2" ;
seq=2 ;
} ;
if( $4 == "null" ){
printf("### %s ### No value for UUID. No file system on this partition.\n\n", $3 ) ;
}else{
printf("# %-12s %-8s %-10s %-38s %-13s %s %s\n", $1, $2, $3, $4, $5, $6, usbPlug ) ;
printf("UUID=%s \t%s \t%s \t%s \t%s \t%s\n\n", $4, "none", $2, perms, "0", seq ) ;
};
}else{
if ( $1 == pROOT ) {
perms="defaults" ;
seq=0 ;
}else{
#perms="nosuid,nodev,nofail,defaults" ;
if( usbPlug == "USB_EXTERNAL" ){
perms="defaults,nofail,noauto" ;
}else{
perms="defaults,nofail" ;
} ;
if ( $1 ~ dROOT ) { seq=1 ; }else{ seq=2 ; } ;
} ;
if( $4 == "null" ){
printf("### %s ### No value for UUID. No file system on this partition.\n\n", $3 ) ;
}else{
printf("# %-12s %-8s %-10s %-38s %-13s %s %s\n", $1, $2, $3, $4, $5, $6, usbPlug ) ;
printf("UUID=%s \t%s \t%s \t%s \t%s \t%s\n\n", $4, $6, $2, perms, "0", seq ) ;
};
} ;
} ;
}'
fi
# Other command format for other properties related to partitions:
# lsblk -o NAME,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,ROTA,SCHED,RQ-SIZE,RA,WSAME
# Other option which is not as complete:
# blkid -o list
if [ -t 1 ] ; then echo "\n\t Done. [`basename $0 `]\n" ; fi
#if [ ! -t 1 ] ; then echo "\t Done. [`basename $0 `]\n" >&2 ; fi
rm -f ${TMP}.*
exit 0
exit 0
exit 0
---- editado ----
Como observarás que tengo un esquema de nombres particular para mis particiones y adapto todas mis herramientas a ese esquema de nombres, aquí está el informe de mi propia versión de "myDf.sh" y el script para hacerlo. Tenga en cuenta las agrupaciones específicas.
---- original en inglés ----
Since you will observe that I have a particular naming scheme for my partitions, and adapt all my tools to that naming scheme, here is the report from my own version of "myDf.sh" and the script to do that. Note the specific groupings.
Informe de "myDf.sh":
root:~# myDf.sh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 192G 67G 115G 37% /
/dev/sda7 289G 247G 27G 91% /DB001_F2
/dev/sda8 289G 251G 23G 92% /DB001_F3
/dev/sda9 289G 250G 25G 92% /DB001_F4
/dev/sda12 192G 168G 15G 93% /DB001_F5
/dev/sda13 192G 157G 26G 87% /DB001_F6
/dev/sda14 288G 140G 134G 52% /DB001_F7
/dev/sda4 92G 22G 66G 25% /DB001_F8
/dev/sdd3 98G 24K 93G 1% /site/DB005_F1
/dev/sdd4 295G 247G 33G 89% /site/DB005_F2
/dev/sdd5 295G 251G 29G 90% /site/DB005_F3
/dev/sdd6 295G 250G 30G 90% /site/DB005_F4
/dev/sdd7 196G 168G 19G 91% /site/DB005_F5
/dev/sdd8 196G 157G 30G 85% /site/DB005_F6
/dev/sdd9 295G 140G 140G 50% /site/DB005_F7
/dev/sdd10 98G 67G 26G 73% /site/DB005_F8
/dev/sdd11 98G 22G 72G 24% /site/DB006_F1
/dev/sdd12 295G 163G 118G 59% /site/DB006_F2
/dev/sdd13 295G 28K 280G 1% /site/DB006_F3
/dev/sdd14 295G 28K 280G 1% /site/DB006_F4
/dev/sdd15 196G 28K 186G 1% /site/DB006_F5
/dev/sdd16 196G 28K 186G 1% /site/DB006_F6
/dev/sdd17 295G 28K 280G 1% /site/DB006_F7
/dev/sdd18 218G 65G 143G 32% /site/DB006_F8
Filesystem Size Used Avail Use% Mounted on
root:~#
Script "myDf.sh":
#!/bin/sh
#########################################################################
###
### $Id: myDf.sh,v 1.4 2020/11/14 02:54:56 root Exp $
###
### Report output of "df" command such that drive labels are sorted alphabetically and all mounted drives are at bottom. Option '--all' reports non-disk filesystems and '--debug' reports raw input before displaying expected report.
###
#########################################################################
#FUTURES: redo list so that root "/" is reported just before others and with its own drive label.
#DevStat=PROD
#2018-03-18
TMP=/tmp/`basename $0 ".sh"`.$$
onlyHard=1
debug=0
mirrors=0
if [ $# -gt 0 ]
then
case $1 in
--mirrors ) mirrors=1 ; shift ;;
--all ) onlyHard=0 ; shift ;;
--debug ) debug=1 ; shift ;;
* ) ;;
esac
fi
rm -f ${TMP}.*
df -h >${TMP}.raw
header=`head -1 ${TMP}.raw `
echo "\n\t${header}" > ${TMP}.2
if [ ${mirrors} -eq 1 ]
then
tail -n +2 ${TMP}.raw | sort -k1,1 | sort -k6,6 > ${TMP}.1
else
tail -n +2 ${TMP}.raw | sort -k6 > ${TMP}.1
if [ ${onlyHard} != 1 ]
then
grep -v '/sd' ${TMP}.1 | grep -v '/site' | sort -n -k1,1 | awk '{ printf("\t%s\n", $0 ) }' >>${TMP}.4
#/dev/sda1 288G 16G 257G 6% /site/DB001_F1
cat ${TMP}.4 | awk 'BEGIN{ INDX=0 }{
REF=substr($1,1,4) ;
if( REF == INDX ){
printf("\t%-12s %7s %5s %5s %4s %s\n", $1, $2, $3, $4, $5, $6 ) ;
}else{
printf("\n\t%-12s %7s %5s %5s %4s %s\n", $1, $2, $3, $4, $5, $6 ) ;
INDX=REF ;
} ;
}' >>${TMP}.2
echo "\n\t${header}" >>${TMP}.2
fi
fi
if [ ${debug} -eq 1 ]
then
cat ${TMP}.1
echo "=========================================\n"
fi
if [ ${mirrors} -eq 1 ]
then
grep '/sd' ${TMP}.1 >>${TMP}.3
cat ${TMP}.3 | awk '{
n=split($6,var,"/") ;
split(var[n],dar,"_") ;
REF=substr(dar[2],2) ; if( length(REF) == 0 ){ REF=0 } ;
printf("%s|%s|%s\n", REF, $6, $0 ) ;
}' | sort | awk -F \| '{ printf("%s\n", $3 ) }' |
awk 'BEGIN{ INDX=-1 }{
p=split($6,var,"/") ;
split(var[p],dar,"_") ;
REF=substr(dar[2],2) ; if( length(REF) == 0 ){ REF=0 } ;
if( REF == INDX ){
printf("\t%-12s %7s %5s %5s %4s %s\n", $1, $2, $3, $4, $5, $6 ) ;
}else{
printf("\n\t%-12s %7s %5s %5s %4s %s\n", $1, $2, $3, $4, $5, $6 ) ;
INDX=REF ;
} ;
}' >>${TMP}.2
echo "\n\t${header}\n" >>${TMP}.2
else
grep '/sd' ${TMP}.1 | grep -v '/site' >>${TMP}.3
grep '/sd' ${TMP}.1 | grep '/site' >>${TMP}.3
cat ${TMP}.3 | awk 'BEGIN{ INDX=0 }{
n=split($6,var,"/") ;
split(var[n],dar,"_") ;
REF=substr(dar[1],5) ;
if( REF == INDX ){
printf("\t%-12s %7s %5s %5s %4s %s\n", $1, $2, $3, $4, $5, $6 ) ;
}else{
printf("\n\t%-12s %7s %5s %5s %4s %s\n", $1, $2, $3, $4, $5, $6 ) ;
INDX=REF ;
} ;
}' >>${TMP}.2
echo "\n\t${header}\n" >>${TMP}.2
fi
cat ${TMP}.2
rm -f ${TMP}.*