Bhoot
Patron
- Joined
- Mar 28, 2015
- Messages
- 241
I will be honest. I don't know much about scripts. So I went to the section containing help and scripts under the post by @Bidule0hm .
I tried to follow the instructions to the exact letter but I guess I did miss something.
Tried running a cron task as root to send email.
edit: Hid email id
Code:
login as: root
root@111.222.333.444's password:
Last login: Wed Feb 10 04:39:21 2016 from 111.222.333.444
FreeBSD 9.3-RELEASE-p31 (FREENAS.amd64) #0 r288272+33bb475: Wed Feb 3 02:19:35 PST 2016
FreeNAS (c) 2009-2015, The FreeNAS Development Team
All rights reserved.
FreeNAS is released under the modified BSD license.
For more information, documentation, help or support, go here:
http://freenas.org
Welcome to FreeNAS
[root@freenas] ~# mkdir scripts
[root@freenas] ~# cd scripts
[root@freenas] ~/scripts# nano -w smart.sh
GNU nano 2.2.6 File: smart.sh
#!/bin/sh
### Parameters ###
logfile="/tmp/smart_report.tmp"
email="abcxyz@gmail.com"
subject="SMART Status Report for FreeNAS"
drives="da0 da1 da2 da3 da4 da5 da6 da7"
tempWarn=40
tempCrit=45
sectorsCrit=10
testAgeWarn=1
warnSymbol="?"
critSymbol="!"
### Set email headers ###
(
echo "To: ${email}"
echo "Subject: ${subject}"
echo "Content-Type: text/html"
echo "MIME-Version: 1.0"
echo -e "\r\n"
) > "$logfile"
### Set email body ###
echo "<pre style=\"font-size:14px\">" >> "$logfile"
###### summary ######
(
echo ""
echo "########## SMART status report summary for all drives ##########"
echo ""
echo "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+------+------+-------+---$
echo "|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |UDMA |Seek |High |Command|Las$
echo "| | | |On |Stop |Retry|Sectors|Pending|Uncorrec|CRC |Errors|Fly |Timeout|Tes$
echo "| | | |Hours|Count|Count| |Sectors|Sectors |Errors| |Writes|Count |Age$
echo "+------+---------------+----+-----+-----+-----+-------+-------+--------+------+------+------+-------+---$
) >> "$logfile"
for drive in $drives
do
(
smartctl -A -i -v 7,hex48 /dev/"$drive" | \
awk -v device="$drive" -v tempWarn="$tempWarn" -v tempCrit="$tempCrit" -v sectorsCrit="$sectorsCrit" \
-v testAgeWarn="$testAgeWarn" -v warnSymbol="$warnSymbol" -v critSymbol="$critSymbol" \
-v lastTestHours="$(smartctl -l selftest /dev/"$drive" | grep "# 1" | awk '{print $9}')" '\
/Serial Number:/{serial=$3} \
/Temperature_Celsius/{temp=$10} \
/Power_On_Hours/{onHours=$10} \
/Start_Stop_Count/{startStop=$10} \
/Spin_Retry_Count/{spinRetry=$10} \
/Reallocated_Sector/{reAlloc=$10} \
/Current_Pending_Sector/{pending=$10} \
/Offline_Uncorrectable/{offlineUnc=$10} \
/UDMA_CRC_Error_Count/{crcErrors=$10} \
/Seek_Error_Rate/{seekErrors=("0x" substr($10,3,4));totalSeeks=("0x" substr($10,7))} \
/High_Fly_Writes/{hiFlyWr=$10} \
/Command_Timeout/{cmdTimeout=$10} \
END {
[ Wrote 107 lines ]
[root@freenas] ~/scripts# chmod + smart.sh
[root@freenas] ~/scripts# ./smart.sh
./smart.sh: Permission denied.
I tried to follow the instructions to the exact letter but I guess I did miss something.
Tried running a cron task as root to send email.
Code:
abcxyz@gmail.com
5:10 AM (9 minutes ago)
to me
/root/scripts/smart.sh: Permission deniededit: Hid email id