-
Notifications
You must be signed in to change notification settings - Fork 2
/
smart-cron
executable file
·83 lines (76 loc) · 2.62 KB
/
smart-cron
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
# Copyright (C) 2012-2023 Glen Pitt-Pladdy
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
# See: https://github.com/glenpp/cacti-smart
#
# Version 20230701
# where to keep the files
STORE=/var/local/snmp
PREFIX=smart-
# what drive pattern to look for
DRIVEPATTERN=/dev/sd
# update smart parameters from a fixed list - this is needed if device order may change
# if this is non-empty we will only check these devices, else we scan all $DRIVEPATTERN devices
#SMARTLIST="
# /dev/disk/by-id/ata-ST3000DM001-...
# /dev/disk/by-id/ata-ST3000DM001-...
# /dev/disk/by-id/ata-ST3000DM001-...
# /dev/disk/by-id/ata-ST3000DM001-...
# /dev/disk/by-id/ata-ST3000DM001-...
# /dev/disk/by-id/ata-ST3000DM001-...
# /dev/disk/by-id/ata-Samsung_SSD_840_EVO_250GB_...
# /dev/disk/by-id/ata-Samsung_SSD_840_EVO_250GB_...
# /dev/disk/by-id/ata-Samsung_SSD_840_EVO_250GB_...
#"
# update smart parameters
if [ -z "$SMARTLIST" ]; then
# Scan for all $DRIVEPATTERN devices
list="a b c d e f g h i j k l m n o p q r s t u v w x y z"
last=`ls ${DRIVEPATTERN}[a-z] ${DRIVEPATTERN}[a-z][a-z] 2>/dev/null | tail -n1`
for dl1 in "" $list; do
for dl2 in $list; do
drive=$DRIVEPATTERN$dl1$dl2
dev=`basename $drive`
if [ -b $drive ]; then
# capture SMART info
/usr/sbin/smartctl --nocheck=idle --all --json=o $drive >$STORE/TMP.$PREFIX$dev.json
else
# make an empty file to keep order
touch $STORE/TMP.$PREFIX$dev.json
fi
mv $STORE/TMP.$PREFIX$dev.json $STORE/$PREFIX$dev.json
[ $drive = $last ] && exit 0
done
done
else
# go through our $SMARTLIST one by one
counter=0
for devfull in $SMARTLIST; do
dev=`basename $devfull`
dev=`printf "%03d-%s" $counter "$dev"`
counter=$(($counter+1))
if [ -b $devfull ]; then
# device exists
/usr/sbin/smartctl --nocheck=idle --all --json=o $devfull >$STORE/TMP.$PREFIX$dev.json
else
# no device - create placeholder file
touch $STORE/TMP.$PREFIX$dev.json
fi
mv $STORE/TMP.$PREFIX$dev.json $STORE/$PREFIX$dev.json
done
fi