forked from Lainports/freebsd-ports
52 lines
1.2 KiB
Bash
52 lines
1.2 KiB
Bash
#!/bin/sh
|
|
# This script is in the public domain. Original author: Garrett Wollman
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
|
|
if [ -r /etc/defaults/periodic.conf ]; then
|
|
. /etc/defaults/periodic.conf
|
|
source_periodic_confs
|
|
fi
|
|
|
|
smartctl=%%PREFIX%%/sbin/smartctl
|
|
: ${daily_status_smartctl_flags="-H"}
|
|
: ${daily_status_smartctl_extra_status_flags="-a"}
|
|
# no default for ${daily_status_smart_devices}
|
|
if [ -z "${daily_status_smart_devices}" ]; then
|
|
: ${daily_status_smart_enabled="NO"}
|
|
else
|
|
: ${daily_status_smart_enabled="YES"}
|
|
fi
|
|
trim_junk="tail -n +4"
|
|
|
|
tmpfile="$(mktemp /var/run/daily.XXXXXXXX)"
|
|
trap "rm -f ${tmpfile}" 0 1 3 15
|
|
|
|
rc=0
|
|
case "${daily_status_smart_enable}" in
|
|
[Nn][Oo])
|
|
;;
|
|
*)
|
|
for device in ${daily_status_smart_devices}; do
|
|
if [ -e ${device} ]; then
|
|
echo
|
|
echo "Checking health of ${device}:"
|
|
echo
|
|
${smartctl} ${daily_status_smartctl_flags} ${device} > "${tmpfile}"
|
|
status=$?
|
|
if [ $((status & 3)) -ne 0 ]; then
|
|
rc=2
|
|
${trim_junk} "${tmpfile}"
|
|
elif [ $status -ne 0 ]; then
|
|
rc=1
|
|
${smartctl} ${daily_status_smartctl_extra_status_flags} ${device} | ${trim_junk}
|
|
else
|
|
${trim_junk} "${tmpfile}"
|
|
fi
|
|
fi
|
|
done
|
|
;;
|
|
esac
|
|
|
|
exit "$rc"
|