Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-admin-essentials
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
etersoft-admin-essentials
Commits
8f6ed82f
Commit
8f6ed82f
authored
Feb 17, 2022
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
print_disk.sh: big improvement
parent
89710ba2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
185 additions
and
17 deletions
+185
-17
functions.sh
hdd/functions.sh
+91
-3
print_disks.sh
hdd/print_disks.sh
+94
-14
No files found.
hdd/functions.sh
View file @
8f6ed82f
...
...
@@ -24,6 +24,7 @@ is_hdd()
print_dev_type
()
{
echo
"
$1
"
|
grep
-q
"/dev/nvme"
&&
echo
"NVME"
&&
return
is_hdd
"
$1
"
&&
echo
"HDD"
||
echo
"SSD"
}
...
...
@@ -34,11 +35,37 @@ get_smart_field()
cat
"
$1
"
|
grep
"
$2
: "
|
tail
-n1
|
sed
-e
"s/.*
$2
: *//g"
}
print_drive_
info
()
print_drive_
vendor
()
{
local
OUT
=
''
local
TF
=
$(
mktemp
)
smartctl
-i
$1
>
$TF
echo
"Model:
$(
get_smart_field
$TF
"Model Family"
)
$(
get_smart_field
$TF
"Device Model"
)
Serial:
$(
get_smart_field
$TF
"Serial Number"
)
Firmware:
$(
get_smart_field
$TF
"Firmware Version"
)
"
OUT
=
"
$(
get_smart_field
$TF
"Model Family"
|
sed
-e
's/ .*//'
)
"
[
-n
"
$OUT
"
]
||
OUT
=
"
$(
get_smart_field
$TF
"Model Number"
|
sed
-e
's/ .*//'
)
"
[
-n
"
$OUT
"
]
||
OUT
=
"
$(
get_smart_field
$TF
"Vendor"
)
"
echo
"
$OUT
"
rm
-f
$TF
}
print_drive_product
()
{
local
OUT
=
''
local
TF
=
$(
mktemp
)
smartctl
-i
$1
>
$TF
OUT
=
"
$(
get_smart_field
$TF
"Device Model"
|
sed
-e
's/ / /'
)
"
[
-n
"
$OUT
"
]
||
OUT
=
"
$(
get_smart_field
$TF
"Model Number"
|
sed
-e
's/ / /'
)
"
[
-n
"
$OUT
"
]
||
OUT
=
"
$(
get_smart_field
$TF
"Product"
)
$(
get_smart_field
$TF
"Revision"
)
"
echo
"
$OUT
"
rm
-f
$TF
}
print_drive_rotation
()
{
local
OUT
=
''
local
TF
=
$(
mktemp
)
smartctl
-i
$1
>
$TF
OUT
=
"
$(
get_smart_field
$TF
"Rotation Rate"
|
sed
-e
's/ .*//'
)
"
echo
"
$OUT
"
rm
-f
$TF
}
...
...
@@ -50,6 +77,7 @@ print_drive_info()
# sdc 0
# sdd 0
# TODO: obsoleted
print_model
()
{
local
dev
=
"
$1
"
...
...
@@ -120,6 +148,66 @@ get_dm_status()
print_serno
()
{
smartctl
-i
"
$1
"
|
grep
"Serial Number: "
|
sed
-e
"s/.*Serial Number: *//g"
|
tail
-c
5
# 'Serial number' for SAS
# 'Serial Number' for SATA
smartctl
-i
"
$1
"
|
grep
-i
"Serial Number: "
|
sed
-e
"s/.*Serial Number: *//gi"
|
tail
-c
5
#hdparm -i "$1" | grep "SerialNo=" | sed -e "s/.*SerialNo=//g" | tail -c 5
}
print_wwn
()
{
# 'Serial number' for SAS
# 'Serial Number' for SATA
smartctl
-i
"
$1
"
|
grep
-i
"LU WWN Device Id: "
|
sed
-e
"s/.*LU WWN Device Id: *//gi"
|
tail
-c
5
#hdparm -i "$1" | grep "SerialNo=" | sed -e "s/.*SerialNo=//g" | tail -c 5
}
list_zpool_drives
()
{
local
i
local
POOLS
=
$(
zpool status
-L
-P
|
grep
"^ pool:"
|
sed
-e
's/^ pool://'
)
#echo $POOLS
for
i
in
$POOLS
;
do
zpool status
-L
-P
$i
|
grep
/dev/ |
while
read
drive status last
;
do
echo
"
$i
$drive
$status
"
done
done
}
get_zpool_by_drive
()
{
list_zpool_drives |
grep
"
$1
"
|
while
read
pool drive status last
;
do
echo
"
$pool
"
done
}
get_zpool_status_by_drive
()
{
list_zpool_drives |
grep
"
$1
"
|
while
read
pool drive status last
;
do
echo
"
$status
"
done
}
list_lvm_drives
()
{
local
i
pvscan 2>/dev/null |
while
read
PV drive VG pool lvm2 last
;
do
[
"
$lvm2
"
=
"lvm2"
]
||
continue
[
"
$PV
"
=
"PV"
]
||
continue
[
"
$VG
"
=
"VG"
]
||
continue
echo
"
$pool
$drive
"
done
}
get_lvm_by_drive
()
{
list_lvm_drives |
grep
"
$1
\$
"
|
while
read
pool drive last
;
do
echo
"
$pool
"
done
}
get_lvm_status_by_drive
()
{
echo
}
hdd/print_disks.sh
View file @
8f6ed82f
#!/bin/sh
# TODO: размер PV, свободное место
# TODO: вынимать данные в базу sqlite и потом уже делать к ней запросы?
VERBOSE
=
[
"
$1
"
=
"-v"
]
&&
VERBOSE
=
1
...
...
@@ -7,6 +10,10 @@ VERBOSE=
.
$(
dirname
$0
)
/functions.sh
.
$(
dirname
$0
)
/outputformat.sh
check_tty
print_md
()
{
local
dev
=
"
$1
"
...
...
@@ -21,45 +28,116 @@ is_lvm()
blkid
"
$1
"
|
grep
-q
"LVM2_member"
}
print_fstype
()
{
blkid
"
$1
"
|
grep
'TYPE="'
|
sed
-e
's|.*TYPE="||'
-e
's|".*||'
|
grep
-v
"^gpt$"
|
grep
-v
"^dos"
|
grep
-v
"member"
}
is_zfs
()
{
blkid
"
$1
"
|
grep
-q
"zfs_member"
}
get_zfs_pool
()
{
blkid
"
$1
"
|
grep
"zfs_member"
|
sed
-e
's|.*LABEL="||'
-e
's|" .*||'
}
print_zfs
()
{
get_zpool_by_drive
"
$1
"
}
health
()
{
fdisk
-l
$1
2>/dev/null
>
/dev/null
}
print_part_type
()
{
local
pd
=
"
$1
"
local
OUT
=
''
local
LVM
=
''
local
MD
=
''
local
FS
=
''
local
ZFS
=
''
if
is_lvm
$pd
;
then
LVM
=
"
$(
get_lvm_by_drive
$pd
)
"
[
-n
"
$LVM
"
]
&&
OUT
=
"
$OUT
LVM
$LVM
"
else
FS
=
"
$(
print_fstype
$pd
)
"
[
-n
"
$FS
"
]
&&
OUT
=
"
$OUT
FS
$FS
"
fi
MD
=
"
$(
print_md
$pd
)
"
if
[
-n
"
$MD
"
]
;
then
OUT
=
"
$OUT
MD
$MD
"
LVM
=
"
$(
get_lvm_by_drive
$MD
)
"
if
[
-n
"
$LVM
"
]
;
then
OUT
=
"
$OUT
→ LVM
$LVM
"
else
FS
=
"
$(
print_fstype
$MD
)
"
[
-n
"
$FS
"
]
&&
OUT
=
"
$OUT
→ FS
$FS
"
fi
fi
ZFS
=
"
$(
print_zfs
$pd
)
"
if
[
-n
"
$ZFS
"
]
;
then
OUT
=
"
$OUT
ZFS
$ZFS
"
else
ZFS
=
$(
get_zfs_pool
$pd
)
[
-n
"
$ZFS
"
]
&&
OUT
=
"
$OUT
$(
pcolor
$BLUE
"unused ZFS
$ZFS
"
)
"
fi
echo
"
$OUT
"
}
echo
>
$0
.log
# FIXME: prepare some unused cache:
for
i
in
/dev/sd?
;
do
for
i
in
/dev/sd?
/dev/nvme0n?
;
do
[
-n
"
$VERBOSE
"
]
&&
echo
#[ -n "$VERBOSE" ] && hdparm -i $i | grep -B2 SerialNo | grep -v "^$"
#SERNO=$(hdparm -i $i | grep SerialNo | sed -e "s/.*SerialNo=//g" | tail -c 5)
SERNO
=
$(
print_serno
${
i
})
#[ -n "$VERBOSE" ] && blkid ${i}1
#LABEL=$(blkid -s LABEL ${i}1 | sed -e 's/.*LABEL="\(.*\)"/\1/') #"
printf
"%s %s
\n
"
"
$i
"
"
$SERNO
"
|
tee
-a
$0
.log
printf
"%s %s
\n
"
"
$i
"
"
$SERNO
"
|
tee
-a
$0
.log
>
/dev/null
done
# TYPE ROT SIZE DEV SER WWN MD/LVM MAN DI
FORMATLINE
=
"%4s %5s %7s %-10s %4s %4s %-18s %-10s %s
\n
"
echo
>
$0
.log.found
echo
echo
"In physical order:"
echo
"
$(
hostname
-s
|
tr
"[a-z]"
"[A-Z]"
)
drives:"
printf
"
$FORMATLINE
"
"TYPE"
"ROTAT"
"SIZE "
" DEVICE"
"SER"
"WWN"
" MD/LVM/FS"
"Manufacture"
"Drive Info"
n
=
1
for
i
in
$PHYSORDER
;
do
printf
"ata%2s. "
"
$n
"
#
printf "ata%2s. " "$n"
if
grep
-q
"
$i
$"
$0
.log
;
then
DEV
=
"
$(
grep
"
$i
$"
$0
.log |
sed
-e
"s| .*||"
)
"
health
$DEV
||
echo
"NACCESS to
$DEV
"
MD
=
"
$(
print_md
$DEV
)
"
# TYPE SIZE DEV SERIAL MD
printf
"%3s %7s %-10s %4s %10s %s
\n
"
"
$(
print_dev_type
$DEV
)
"
"
$(
print_size
$DEV
)
"
"
$DEV
"
"
$(
print_serno
$DEV
)
"
"
$MD
"
"
$(
print_drive_info
$DEV
)
"
if
[
-z
"
$MD
"
]
;
then
for
pd
in
$DEV
*
;
do
MD
=
"
$(
print_md
$pd
)
"
if
[
-z
"
$MD
"
]
;
then
is_lvm
$pd
&&
MD
=
"LVM2"
OUT
=
"
$(
print_part_type
$DEV
)
"
MDINFO
=
"
$OUT
"
if
!
test
-r
"
$(
ls
-1
$DEV
?
*
2>/dev/null |
head
-n1
)
"
&&
[
-z
"
$OUT
"
]
;
then
MDINFO
=
" UNUSED"
fi
printf
"
$FORMATLINE
"
"
$(
print_dev_type
$DEV
)
"
"
$(
print_drive_rotation
$DEV
)
"
"
$(
print_size
$DEV
)
"
"
$(
basename
$DEV
)
"
"
$(
print_serno
$DEV
)
"
"
$(
print_wwn
$DEV
)
"
"
$MDINFO
"
"
$(
print_drive_vendor
$DEV
)
"
"
$(
print_drive_product
$DEV
)
"
if
[
-z
"
$OUT
"
]
;
then
for
pd
in
$DEV
?
*
;
do
[
-r
$pd
]
||
continue
OUT
=
"
$(
print_part_type
$pd
)
"
MDINFO
=
"
$OUT
"
if
[
-z
"
$OUT
"
]
;
then
MDINFO
=
" UNUSED"
fi
SIZE
=
"
$(
print_partsize
$pd
)
"
if
[
"
$SIZE
"
=
"0 GB"
]
;
then
continue
fi
[
-n
"
$MD
"
]
||
continue
printf
" %3s %7s %-10s %4s %10s
\n
"
""
"
$(
print_partsize
$pd
)
"
"
$pd
"
""
"
$MD
"
printf
"
$FORMATLINE
"
""
""
"
$SIZE
"
"
$(
basename
$pd
)
"
""
""
"
$MDINFO
"
done
fi
grep
"
$i
$"
$0
.log
>>
$0
.log.found
...
...
@@ -91,6 +169,8 @@ sort <$0.log >$0.log.sort
sort
<
$0
.log.found
>
$0
.log.found.sort
diff
-u
$0
.log.sort
$0
.log.found.sort
# TODO
exit
echo
echo
"Drives nor in active RAID nor in LVM:"
for
dev
in
/dev/sd
*
;
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment