Problem with my cron jobs scripts either not working or no format

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i had 3 scripts which worked on 11.2 when i updated to 11.3 they would not email me. somebody said it was a bug and said to comment out

echo "Content-Type: text/html"

This worked and i received the emails with the text format okay.

now i have updated to 11.3-U1 and now the text is all wrong - missing the header and out of line.

Code:
<pre style="font-size:14px">

########## SMART status report summary for all drives ##########

+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|Device|Serial |Temp|Power|Start|Spin |ReAlloc|Current|Offline |Seek |Total |High |Command|
| | | |On |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks |Fly |Timeout|
| | | |Hours|Count|Count| |Sectors|Sectors | | |Writes|Count |
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+
|ada0 |BTPR251404F5040AGN| |53854| 0| | 0| | | N/A| N/A| N/A| N/A|
|ada1 |WD-WMC4N0F63AAE | 31 |43898| 203| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|ada2 |WD-WCC4NNPTEN30 | 30 |47229| 235| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|ada3 |CVPR119203RX040AGN| |64977| 0| | 0| | | N/A| N/A| N/A| N/A|
|ada4 |WD-WCC4N0598278 | 30 |50854| 247| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|ada5 |WD-WCC4N0594308 | 30 |51032| 252| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da0 |WD-WCC4NLATJSJD | 31 |47063| 228| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da1 |WD-WCC4N2LUY75H | 30 |25873| 63| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da2 |7SJG44HW | 32 |10714| 35| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da3 |7HK8K7JF | 33 | 8277| 22| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da4 |1SGMVWBZ | 33 |16695| 58| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da5 |7SHTTZPW | 32 |14899| 45| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da6 |JEJM1X2N | 33 | 1731| 7| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
|da7 |2SG052WF | 33 | 1731| 8| 0| 0| 0| 0| N/A| N/A| N/A| N/A|
+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+


Code:
#!/bin/sh

### Parameters ###
logfile="/tmp/smart_report.tmp"
email="ethereal9@gmail.com"
subject="SMART Status Report"
drives=$(for drive in $(sysctl -n kern.disks); do \
if [ "$(smartctl -i /dev/${drive} | grep "Serial Number" | awk '{print $3}')" ]
then printf ${drive}" "; fi done | awk '{for (i=NF; i!=0 ; i--) print $i }')
tempWarn=40
tempCrit=45
sectorsCrit=10
warnSymbol="?"
critSymbol="!"

### Set email headers ###
(
    echo "To: ${email}"
    echo "Subject: ${subject}"
Rem    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 |Seek  |Total     |High  |Command|"
    echo "|      |                  |    |On   |Stop |Retry|Sectors|Pending|Uncorrec|Errors|Seeks     |Fly   |Timeout|"
    echo "|      |                  |    |Hours|Count|Count|       |Sectors|Sectors |      |          |Writes|Count  |"
    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 warnSymbol=${warnSymbol} -v critSymbol=${critSymbol} '\
        /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} \
        /Seek_Error_Rate/{seekErrors=("0x" substr($10,3,4));totalSeeks=("0x" substr($10,7))} \
        /High_Fly_Writes/{hiFlyWr=$10} \
        /Command_Timeout/{cmdTimeout=$10} \
        END {
            if (temp > tempCrit || reAlloc > sectorsCrit || pending > sectorsCrit || offlineUnc > sectorsCrit)
                device=device " " critSymbol;
            else if (temp > tempWarn || reAlloc > 0 || pending > 0 || offlineUnc > 0)
                device=device " " warnSymbol;
            seekErrors=sprintf("%d", seekErrors);
            totalSeeks=sprintf("%d", totalSeeks);
            if (totalSeeks == "0") {
                seekErrors="N/A";
                totalSeeks="N/A";
            }
            if (hiFlyWr == "") hiFlyWr="N/A";
            if (cmdTimeout == "") cmdTimeout="N/A";
            printf "|%-6s|%-18s| %s |%5s|%5s|%5s|%7s|%7s|%8s|%6s|%10s|%6s|%7s|\n",
            device, serial, temp, onHours, startStop, spinRetry, reAlloc, pending, offlineUnc, \
            seekErrors, totalSeeks, hiFlyWr, cmdTimeout;
        }'
    ) >> ${logfile}
done
(
    echo "+------+------------------+----+-----+-----+-----+-------+-------+--------+------+----------+------+-------+"
    echo ""
    echo ""
) >> ${logfile}

###### for each drive ######
for drive in $drives
do
    brand=`smartctl -i /dev/${drive} | grep "Model Family" | awk '{print $3, $4, $5}'`
    if [ -z "$brand" ];
    then
      brand=`smartctl -i /dev/${drive} | grep "Device Model" | awk '{print $3, $4, $5}'`
    fi
    serial=`smartctl -i /dev/${drive} | grep "Serial Number" | awk '{print $3}'`
    (
        echo ""
        echo "########## SMART status report for ${drive} drive (${brand}: ${serial}) ##########"
        smartctl -n never -H -A -l error /dev/${drive}
        smartctl -n never -l selftest /dev/${drive}
        echo ""
        echo ""
    ) >> ${logfile}
done
sed -i '' -e '/smartctl 6.3/d' ${logfile}
sed -i '' -e '/Copyright/d' ${logfile}
sed -i '' -e '/=== START OF READ/d' ${logfile}
sed -i '' -e '/SMART Attributes Data/d' ${logfile}
sed -i '' -e '/Vendor Specific SMART/d' ${logfile}
sed -i '' -e '/SMART Error Log Version/d' ${logfile}
echo "</pre>" >> ${logfile}

### Send report ###
sendmail -t < ${logfile}
rm ${logfile}


Code:
#!/bin/sh
 
### Parameters ###
logfile="/tmp/zpool_report.tmp"
email="ethereal9@gmail.com"
subject="ZPool Status Report for FreeNAS"
pools="freenas-boot Storage Working"
usedWarn=75
usedCrit=90
scrubAgeWarn=30
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 "########## ZPool status report summary for all pools ##########"
    echo ""
    echo "+--------------+--------+------+------+------+----+--------+------+-----+"
    echo "|Pool Name     |Status  |Read  |Write |Cksum |Used|Scrub   |Scrub |Last |"
    echo "|              |        |Errors|Errors|Errors|    |Repaired|Errors|Scrub|"
    echo "|              |        |      |      |      |    |Bytes   |      |Age  |"
    echo "+--------------+--------+------+------+------+----+--------+------+-----+"
) >> "$logfile"
for pool in $pools; do
    status="$(zpool list -H -o health "$pool")"
    errors="$(zpool status "$pool" | egrep "(ONLINE|DEGRADED|FAULTED|UNAVAIL|REMOVED)[ \t]+[0-9]+")"
   readErrors=0
   for err in $(echo "$errors" | awk '{print $3}'); do
       if echo "$err" | egrep -q "[^0-9]+"; then
           readErrors=1000
           break
       fi
       readErrors=$((readErrors + err))
   done
   writeErrors=0
   for err in $(echo "$errors" | awk '{print $4}'); do
       if echo "$err" | egrep -q "[^0-9]+"; then
           writeErrors=1000
           break
       fi
       writeErrors=$((writeErrors + err))
   done
   cksumErrors=0
   for err in $(echo "$errors" | awk '{print $5}'); do
       if echo "$err" | egrep -q "[^0-9]+"; then
           cksumErrors=1000
           break
       fi
       cksumErrors=$((cksumErrors + err))
   done
   if [ "$readErrors" -gt 999 ]; then readErrors=">1K"; fi
   if [ "$writeErrors" -gt 999 ]; then writeErrors=">1K"; fi
   if [ "$cksumErrors" -gt 999 ]; then cksumErrors=">1K"; fi
   used="$(zpool list -H -p -o capacity "$pool")"
   scrubRepBytes="N/A"
   scrubErrors="N/A"
   scrubAge="N/A"
   if [ "$(zpool status "$pool" | grep "scan" | awk '{print $2}')" = "scrub" ]; then
       scrubRepBytes="$(zpool status "$pool" | grep "scan" | awk '{print $4}')"
       scrubErrors="$(zpool status "$pool" | grep "scan" | awk '{print $10}')"
       scrubDate="$(zpool status "$pool" | grep "scan" | awk '{print $17"-"$14"-"$15"_"$16}')"
       scrubTS="$(date -j -f "%Y-%b-%e_%H:%M:%S" "$scrubDate" "+%s")"
       currentTS="$(date "+%s")"
       scrubAge=$((((currentTS - scrubTS) + 43200) / 86400))
   fi
   if [ "$status" = "FAULTED" ] \
   || [ "$used" -gt "$usedCrit" ] \
   || ( [ "$scrubErrors" != "N/A" ] && [ "$scrubErrors" != "0" ] )
   then
       symbol="$critSymbol"
   elif [ "$status" != "ONLINE" ] \
   || [ "$readErrors" != "0" ] \
   || [ "$writeErrors" != "0" ] \
   || [ "$cksumErrors" != "0" ] \
   || [ "$used" -gt "$usedWarn" ] \
   || [ "$scrubRepBytes" != "0" ] \
   || [ "$(echo "$scrubAge" | awk '{print int($1)}')" -gt "$scrubAgeWarn" ]
   then
       symbol="$warnSymbol"
   else
       symbol=" "
   fi
   (
       printf "|%-12s %1s|%-8s|%6s|%6s|%6s|%3s%%|%8s|%6s|%5s|\n" \
       "$pool" "$symbol" "$status" "$readErrors" "$writeErrors" "$cksumErrors" \
       "$used" "$scrubRepBytes" "$scrubErrors" "$scrubAge"
   ) >> "$logfile"
done
(
   echo "+--------------+--------+------+------+------+----+--------+------+-----+"
   echo ""
   echo ""
) >> "$logfile"
 
###### for each pool ######
for pool in $pools; do
   (
       echo ""
       echo "########## ZPool status report for ${pool} ##########"
        echo ""
        zpool status -v "$pool"
        echo ""
        echo ""
    ) >> "$logfile"
done
 
echo "</pre>" >> "$logfile"
 
### Send report ###
sendmail -t < "$logfile"
rm "$logfile"



Code:
#!/bin/sh

### Parameters ###
logfile="/tmp/ups_report.tmp"
email="ethereal9@gmail.com"
subject="UPS Status Report for FreeNAS"
ups="ups@localhost"

### 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\">"
    echo ""
    date "+Time: %Y-%m-%d %H:%M:%S"
    echo "UPS Status: `upsc ${ups} ups.status`"
    echo "Output Load: `upsc ${ups} ups.load` %"
    echo "Output Voltage: `upsc ${ups} output.voltage` V"
    echo "Battery Runtime: `upsc ${ups} battery.runtime` s"
    echo "Battery Charge: `upsc ${ups} battery.charge` %"
    echo ""
    echo "</pre>"
) >> ${logfile}

### Send report ###
sendmail -t < ${logfile}
rm ${logfile}


hopefully someone can help at the moment if i comment out:- echo "Content-Type: text/html" The email is delivered but unintelligible.

if i remove the comment the email is not sent.

i thought if it was a known bug it would be fixed in 11.3-U1 rather than making things worse for me
 
Last edited:

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
it been solved here.
thank you
 
Top