#!/bin/sh -e
# 
# run the specified selftest for all devices listed $run_cron_selftests
# iff smartd is running
#
# (C) 2003 Guido Guenther <agx@sigxcpu.org>

CONF=/etc/default/smartmontools
[ -r $CONF ] && . $CONF
[ ! "$run_cron_selftests" ] && exit 0

SELFTEST=${1:-short}
SELFTEST_OPTS="-q errorsonly -t $SELFTEST"
SMARTD_PID=/var/run/smartd.pid
SMARTCTL=/usr/sbin/smartctl

if [ -f $SMARTD_PID -a -x $SMARTCTL ]; then
    for i in $run_cron_selftests; do
    	$SMARTCTL $SELFTEST_OPTS $i
    done
fi
