Script for Periodic Email Notification of unRAID Status


Recommended Posts

Do you get any of the text above the mdcmd section?

 

On mine, I get this above the "mdcmd section"

This message is a status update for unRAID Tower

-----------------------------------------------------------------

Server Name: Tower

Server IP: 192.168.2.100

Status: unRaid is OK

Date: Fri Jul 11 19:09:45 EDT 2008

Status: unRaid is OK

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 978M 500M 478M 52% /boot

/dev/md4 373G 364G 9.6G 98% /mnt/disk4

/dev/md2 373G 360G 13G 97% /mnt/disk2

/dev/md5 373G 323G 51G 87% /mnt/disk5

/dev/md3 466G 443G 24G 95% /mnt/disk3

/dev/md6 373G 363G 10G 98% /mnt/disk6

/dev/md8 466G 243G 224G 53% /mnt/disk8

/dev/md7 466G 458G 8.2G 99% /mnt/disk7

/dev/md1 466G 460G 6.2G 99% /mnt/disk1

/dev/md9 234G 224G 11G 96% /mnt/disk9

/dev/md10 699G 679G 20G 98% /mnt/disk10

shfs 4.2T 3.9T 374G 92% /mnt/user

 

Output of /proc/mdcmd:

-----------------------------------------------------------------

...

...

 

I suspect that the output of mdcmd is triggering the end of the e-mail text.  Normally, it is a line with a single period by itself.

 

Can you type the following commands and capture the output for me?

strings </proc/mdcmd | todos

Link to comment
  • 2 weeks later...
  • Replies 87
  • Created
  • Last Reply

Top Posters In This Topic

Thanks for the reply and all the help.  I do NOT get any of the text above the mdcmd section.  That is the information I'm hoping to get ultimately with your help if possible. 

 

Here is the output of the command --

root@Tower:/boot# strings </proc/mdcmd | todos
cmdOper=status
cmdResult=ok
sbName=/boot/config/super.dat
sbVersion=0.94.0
sbCreated=1213816671
sbUpdated=1216970863
sbEvents=127
sbState=0
sbNumDisks=12
sbSynced=1216132889
sbSyncErrs=0
mdVersion=0.94.0
mdState=STARTED
mdNumProtected=11
mdNumDisabled=0
mdDisabledDisk=0
mdNumInvalid=0
mdInvalidDisk=0
mdNumMissing=0
mdMissingDisk=0
mdNumNew=0
mdResync=0
diskNumber.0=0
diskName.0=
diskState.0=7
diskSize.0=976762552
diskModel.0=MAXTOR STM310003
diskSerial.0=9QJ0G5RG
diskNumReads.0=30866
diskNumWrites.0=31057
diskNumErrors.0=0
diskId.0=ata-MAXTOR_STM310003_9QJ0G5RG
rdevNumber.0=0
rdevStatus.0=DISK_OK
rdevName.0=sdh
rdevSize.0=976762552
rdevModel.0=MAXTOR STM31000340AS                    
rdevSerial.0=            9QJ0G5RG
rdevId.0=ata-MAXTOR_STM31000340AS_9QJ0G5RG
diskNumber.1=1
diskName.1=md1
diskState.1=7
diskSize.1=976762552
diskModel.1=WDC WD10EACS-00D
diskSerial.1=WD-WCAU40229133
diskNumReads.1=2786980
diskNumWrites.1=12
diskNumErrors.1=0
diskId.1=ata-WDC_WD10EACS-00D_WD-WCAU40229133
rdevNumber.1=1
rdevStatus.1=DISK_OK
rdevName.1=sdj
rdevSize.1=976762552
rdevModel.1=WDC WD10EACS-00D6B0                     
rdevSerial.1=     WD-WCAU40229133
rdevId.1=ata-WDC_WD10EACS-00D6B0_WD-WCAU40229133
diskNumber.2=2
diskName.2=md2
diskState.2=7
diskSize.2=976762552
diskModel.2=WDC WD10EACS-00D
diskSerial.2=WD-WCAU40196412
diskNumReads.2=343729
diskNumWrites.2=15
diskNumErrors.2=0
diskId.2=ata-WDC_WD10EACS-00D_WD-WCAU40196412
rdevNumber.2=2
rdevStatus.2=DISK_OK
rdevName.2=sda
rdevSize.2=976762552
rdevModel.2=WDC WD10EACS-00D6B0                     
rdevSerial.2=     WD-WCAU40196412
rdevId.2=ata-WDC_WD10EACS-00D6B0_WD-WCAU40196412
diskNumber.3=3
diskName.3=md3
diskState.3=7
diskSize.3=732574552
diskModel.3=ST3750640AS     
diskSerial.3=5QD03RVW
diskNumReads.3=159
diskNumWrites.3=15
diskNumErrors.3=0
diskId.3=ata-ST3750640AS_5QD03RVW
rdevNumber.3=3
rdevStatus.3=DISK_OK
rdevName.3=sdi
rdevSize.3=732574552
rdevModel.3=ST3750640AS                             
rdevSerial.3=            5QD03RVW
rdevId.3=ata-ST3750640AS_5QD03RVW
diskNumber.4=4
diskName.4=md4
diskState.4=7
diskSize.4=732574552
diskModel.4=ST3750640AS     
diskSerial.4=5QD03GC1
diskNumReads.4=126
diskNumWrites.4=15
diskNumErrors.4=0
diskId.4=ata-ST3750640AS_5QD03GC1
rdevNumber.4=4
rdevStatus.4=DISK_OK
rdevName.4=sde
rdevSize.4=732574552
rdevModel.4=ST3750640AS                             
rdevSerial.4=            5QD03GC1
rdevId.4=ata-ST3750640AS_5QD03GC1
diskNumber.5=5
diskName.5=
diskState.5=0
diskSize.5=0
diskModel.5=
diskSerial.5=
diskNumReads.5=0
diskNumWrites.5=0
diskNumErrors.5=0
diskId.5=ata-_
rdevNumber.5=5
rdevStatus.5=DISK_NP
rdevName.5=
rdevSize.5=0
rdevModel.5=
rdevSerial.5=
rdevId.5=ata-_
diskNumber.6=6
diskName.6=md6
diskState.6=7
diskSize.6=732574552
diskModel.6=ST3750640AS     
diskSerial.6=5QD02WEA
diskNumReads.6=144
diskNumWrites.6=12
diskNumErrors.6=0
diskId.6=ata-ST3750640AS_5QD02WEA
rdevNumber.6=6
rdevStatus.6=DISK_OK
rdevName.6=sdl
rdevSize.6=732574552
rdevModel.6=ST3750640AS                             
rdevSerial.6=            5QD02WEA
rdevId.6=ata-ST3750640AS_5QD02WEA
diskNumber.7=7
diskName.7=md7
diskState.7=7
diskSize.7=732574552
diskModel.7=ST3750640AS     
diskSerial.7=5QD02SPD
diskNumReads.7=63
diskNumWrites.7=15
diskNumErrors.7=0
diskId.7=ata-ST3750640AS_5QD02SPD
rdevNumber.7=7
rdevStatus.7=DISK_OK
rdevName.7=sdg
rdevSize.7=732574552
rdevModel.7=ST3750640AS                             
rdevSerial.7=            5QD02SPD
rdevId.7=ata-ST3750640AS_5QD02SPD
diskNumber.8=8
diskName.8=md8
diskState.8=7
diskSize.8=488386552
diskModel.8=HDS725050KLA360 
diskSerial.8=KRVN65ZAGLVN7F
diskNumReads.8=1206670
diskNumWrites.8=217
diskNumErrors.8=0
diskId.8=ata-HDS725050KLA360_KRVN65ZAGLVN7F
rdevNumber.8=8
rdevStatus.8=DISK_OK
rdevName.8=sdb
rdevSize.8=488386552
rdevModel.8=HDS725050KLA360                         
rdevSerial.8=      KRVN65ZAGLVN7F
rdevId.8=ata-HDS725050KLA360_KRVN65ZAGLVN7F
diskNumber.9=9
diskName.9=md9
diskState.9=7
diskSize.9=488386552
diskModel.9=HDS725050KLA360 
diskSerial.9=KRVN65ZAGP72SF
diskNumReads.9=83
diskNumWrites.9=15
diskNumErrors.9=0
diskId.9=ata-HDS725050KLA360_KRVN65ZAGP72SF
rdevNumber.9=9
rdevStatus.9=DISK_OK
rdevName.9=sdk
rdevSize.9=488386552
rdevModel.9=HDS725050KLA360                         
rdevSerial.9=      KRVN65ZAGP72SF
rdevId.9=ata-HDS725050KLA360_KRVN65ZAGP72SF
diskNumber.10=10
diskName.10=md10
diskState.10=7
diskSize.10=488386552
diskModel.10=HDS725050KLA360 
diskSerial.10=KRVN65ZAGR2S7F
diskNumReads.10=2068787
diskNumWrites.10=15
diskNumErrors.10=0
diskId.10=ata-HDS725050KLA360_KRVN65ZAGR2S7F
rdevNumber.10=10
rdevStatus.10=DISK_OK
rdevName.10=sdf
rdevSize.10=488386552
rdevModel.10=HDS725050KLA360                         
rdevSerial.10=      KRVN65ZAGR2S7F
rdevId.10=ata-HDS725050KLA360_KRVN65ZAGR2S7F
diskNumber.11=11
diskName.11=md11
diskState.11=7
diskSize.11=488386552
diskModel.11=ST3500641AS     
diskSerial.11=3PM0DJRK
diskNumReads.11=387992
diskNumWrites.11=30743
diskNumErrors.11=0
diskId.11=ata-ST3500641AS_3PM0DJRK
rdevNumber.11=11
rdevStatus.11=DISK_OK
rdevName.11=sdc
rdevSize.11=488386552
rdevModel.11=ST3500641AS                             
rdevSerial.11=            3PM0DJRK
rdevId.11=ata-ST3500641AS_3PM0DJRK

 

Thanks very much.

Link to comment
  • 1 month later...

you might try to add a line to your /etc/resolv.conf file

echo "nameserver x.x.x.x" >/etc/resolv.conf

 

where x.x.x.x is the IP of your DNS.   In my case, the DNS is the IP of my router.

If it works, put it as one more line at the end of your "go" script.

 

Did the authentication work in the smtp mail as I had scripted it using the base64 login and password?   Do you now get e-mail messages when the array is stopped (at roughly 47 minutes past the hour) or when you invoke the script by hand?

 

Joe L.

 

I tried this but it still only works if I manually enter my smtp servers IP address in the script like ???.  If I enter

 

cat /etc/resolv.conf

 

it returns

 

192.168.1.1

 

which is the address of my router.  It seems like it should work, but it doesn't.  Anyone have any idea why?

Link to comment

you might try to add a line to your /etc/resolv.conf file

echo "nameserver x.x.x.x" >/etc/resolv.conf

 

where x.x.x.x is the IP of your DNS.   In my case, the DNS is the IP of my router.

If it works, put it as one more line at the end of your "go" script.

 

Did the authentication work in the smtp mail as I had scripted it using the base64 login and password?   Do you now get e-mail messages when the array is stopped (at roughly 47 minutes past the hour) or when you invoke the script by hand?

 

Joe L.

 

I tried this but it still only works if I manually enter my smtp servers IP address in the script like ???.  If I enter

 

cat /etc/resolv.conf

 

it returns

 

192.168.1.1

 

which is the address of my router.  It seems like it should work, but it doesn't.  Anyone have any idea why?

When I do the same, it does:

root@Tower:/boot# cat /etc/resolv.conf

nameserver 192.168.2.1

 

Are you missing the word "nameserver" in front of the IP address perhaps?

Link to comment

You're right I was missing that, but the script still won't work without the IP manually entered.  Here's what i get:

 

Tower1 login: root
Linux 2.6.24.4-unRAID.
root@Tower1:~# cat /etc/resolv.conf
nameserver 192.168.1.1
root@Tower1:~# smtp_check_unraid
-bash: smtp_check_unraid: command not found
root@Tower1:~# cd /boot
root@Tower1:/boot# smtp_check_unraid.sh
root@Tower1:/boot# sh -xv /boot/smtp_check_unraid.sh 2>&1 | tee /boot/smtp_check.log
#!/bin/bash
#
# Title: smtp_check_status.sh
#
# Summary:
# The purpose of this script is to check the status of the unRAID
# array by searching the /proc/mdcmd file for known bad states.
# This script was originally created by Joe. L for use with Yak
# and has been modified by kenshin (twelston) on 08-17-2007 to add smtp
# functionality, and increase the information transmitted by the script
# (i.e. adding ip, date, and the output of the /proc/mdcmd file if
# elected by the user)
#
# If you have any questions or problems while using this script please
# post them to the unRaid forum:
#
# http://support.lime-technology.com/forum/
#
# DISCLAIMER:
# Your use of this script is at your sole risk. This script is provided
#  "as -is", without any warranty
#
# Further, the authors of this script shall not be liable for any damages
# you may sustain by using this information, whether direct, indirect,
# special, incidental or consequential, even if they have been advised of
# the possibility of such damages.

# Define the following six values to setup this script

# The name of your SMTP server
sSmtpServer="smtp.myisp.com"
+ sSmtpServer=smtp.myisp.com

# Your domain name
sDomain="www.neo.rr.com"
+ sDomain=www.neo.rr.com

# The "from" email address
sMailFrom="[email protected]"
+ [email protected]

# The "to" mail address (The addressess must be separated by a space, a
# single address requires no spaces)
sRcptTo="[email protected]"
+ [email protected]

# The email subject
sSubject="unRaid Status Notification"
+ sSubject='unRaid Status Notification'

# Choose whether to include the contents of /proc/mdcmd in your status
# notifications (Setting this value to anything but "True" is the same
# as setting it to "False")
bIncludeMdcmd="True"
+ bIncludeMdcmd=True

# A copy of netcat (nc) is on the flash drive, add /boot/ to the PATH so it
# will be found when executed.
PATH=$PATH:/boot/
+ PATH=/usr/local/sbin:/usr/sbin:/sbin:./:/usr/local/bin:/usr/bin:/bin:/boot/

# initialize the error message to an empty string if no hourly OK message is desired
# like this:
#emsg=""
emsg=""
+ emsg=

# request that status be updated
echo "status" >/proc/mdcmd
+ echo status
# now check the status and report as needed
# Even if the contents of /proc/mdcmd are not normally included if all is OK,
# include it if something is wrong by setting the flag to True.
grep "mdState=STARTED" /proc/mdcmd >/dev/null 2>&1
+ grep mdState=STARTED /proc/mdcmd
if [ $? != 0 ]
then
        emsg="unRaid array not started"
        bIncludeMdcmd="True"
fi
+ '[' 0 '!=' 0 ']'

egrep "=DISK_INVALID|=DISK_DSBL" /proc/mdcmd >/dev/null 2>&1
+ egrep '=DISK_INVALID|=DISK_DSBL' /proc/mdcmd
if [ $? = 0 ]
then
        emsg="The unRaid array needs attention. One or more disks are disabled or invalid."
        bIncludeMdcmd="True"
fi
+ '[' 1 = 0 ']'

# RESYNC MESSAGES
P=${0##*/}              # basename of program
+ P=smtp_check_unraid.sh
R=${0%%$P}          # dirname of program
+ R=/boot/
P=${P%.*}              # strip off after last . character
+ P=smtp_check_unraid
export T=/tmp/${P}.$$
+ export T=/tmp/smtp_check_unraid.2039
+ T=/tmp/smtp_check_unraid.2039
trap "rm -f ${T}" EXIT HUP INT QUIT
+ trap 'rm -f /tmp/smtp_check_unraid.2039' EXIT HUP INT QUIT
strings < /proc/mdcmd > ${T}
+ strings
RESYNC=`egrep "^mdResync" ${T} | cut -d "=" -f2`
egrep "^mdResync" ${T} | cut -d "=" -f2
++ egrep '^mdResync' /tmp/smtp_check_unraid.2039
++ cut -d = -f2
+ RESYNC=0
if [ "$RESYNC" != "0" ]
then RESYNCPERCENT=`egrep "^mdResyncPrcnt" ${T} | cut -d "=" -f2`
     RESYNCFINISH=`egrep "^mdResyncFinish" ${T} | cut -d "=" -f2`
     RESYNCSPEED=`egrep "^mdResyncSpeed"  ${T} | cut -d "=" -f2`
     NL=`echo "\n"`
     sSubject="unRaid Resync Notification"
     emsg="The unRaid array is resync/rebuilding parity.${NL}${NL}"
     if [ ! -z "${RESYNCPERCENT}" ]
        then emsg="${emsg}Parity CHECK/RESYNC in progress, "
             emsg="${emsg} ${RESYNCPERCENT}% complete, "
             emsg="${emsg} est. finish in $RESYNCFINISH minutes."
             emsg="${emsg} Speed: ${RESYNCSPEED} kb/s."
     fi
     bIncludeMdcmd="False"
fi
+ '[' 0 '!=' 0 ']'

# if an error message was set, broadcast it to all the email addresses
# in the notify list
if [ "$emsg" != "" ]
then
        # look up the ip address given the machine name
        ip_addr=`net lookup $sSmtpServer 2>/dev/null`
        if [ $? = 0 ]
        then

        # Build the echo string
        sEcho="ehlo $sDomain\r\nmail from:$sMailFrom\r\n"

        # Add each recipient to the RCPT list
        for i in $sRcptTo
        do
                sEcho+="RCPT TO:"$i"\r\n"
        done

        # Message header
        sEcho+="data\r\nFrom:$sMailFrom\r\nTo:"

        # Add each recipient to the message header
        for i in $sRcptTo
        do
                sEcho+=$i";"
        done

        sEcho+="\r\n"

        # Message Subject
        sEcho+="Subject:$sSubject\r\n"

        # Message Body (You can change this to look how you want.  Just
        #              to include \r\n at the end of each line.)
        sEcho+="This message is a status update for unRAID  $HOSTNAME\r\n"
        sEcho+="-----------------------------------------------------------------\r\n"
        sEcho+="Server Name: $HOSTNAME\r\n"
        sEcho+="Server IP: `net lookup $HOSTNAME 2>/dev/null`\r\n"
        sEcho+="Status: $emsg\r\n"
        sEcho+="Date: "
        sEcho+=`date 2>/dev/null`
        sEcho+="\r\n"

        # Add the contents of /proc/mdcmd if elected by the user
        if [ "$bIncludeMdcmd" = "True" ]
        then
                sEcho+="\r\n"
                sEcho+="Output of /proc/mdcmd:\r\n"
                sEcho+="-----------------------------------------------------------------\r\n"

                # Add <CRLF> to each line
                file=/proc/mdcmd
                sEcho+=`sed "s/$/\\r\\n/" <$file`
                sEcho+="\r\n"
        fi
        # End the message
        sEcho+=".\r\n"
        sEcho+="QUIT\r\n"
        # Send the message we just built

        echo -e $sEcho|nc -i 1 -q 1 $ip_addr 25

        # Use the following line for debug
        #echo -e $sEcho|nc -w 1 -q 2 -i 1 -vv $ip_addr 25
        fi
fi
+ '[' '' '!=' '' ']'



rm -f /tmp/smtp_check_unraid.2039
+ rm -f /tmp/smtp_check_unraid.2039
root@Tower1:/boot#

 

Link to comment

It appeared to work perfectly fine.  You have it set up to only send a notification if the array is off-line or has a disk failure.  From whst I can see, no abnormal status was detected.

 

The lines at the top where "emsg" is defined can be changed if you want a success notification for these tests, or, you can stop your array and retry the script with it stopped.

 

To force a message to be sent every time the script is run, change the following lines:

 

# initialize the error message to an empty string if no hourly OK message is desired

# like this:

#emsg=""

emsg=""

to

 

# initialize the error message to an empty string if no hourly OK message is desired

# like this:

#emsg=""

emsg="The unRAID server is alive and well."

 

 

 

To test if the nameserver is working, type

net lookup google.com

 

it should come back with an IP address. 

 

Joe L.

Link to comment

It's different this time but here it is again:

 

+ '[' '' '!=' '' ']'



rm -f /tmp/smtp_check_unraid.2039
+ rm -f /tmp/smtp_check_unraid.2039
root@Tower1:/boot#
root@Tower1:/boot# net lookup google.com
64.233.167.99
root@Tower1:/boot# net lookup smtp-server.neo.rr.com
75.180.132.33
root@Tower1:/boot# smtp_check_unraid.sh
root@Tower1:/boot# sh -xv /boot/smtp_check_unraid.sh 2>&1 | tee /boot/smtp_check.log
#!/bin/bash
#
# Title: smtp_check_status.sh
#
# Summary:
# The purpose of this script is to check the status of the unRAID
# array by searching the /proc/mdcmd file for known bad states.
# This script was originally created by Joe. L for use with Yak
# and has been modified by kenshin (twelston) on 08-17-2007 to add smtp
# functionality, and increase the information transmitted by the script
# (i.e. adding ip, date, and the output of the /proc/mdcmd file if
# elected by the user)
#
# If you have any questions or problems while using this script please
# post them to the unRaid forum:
#
# http://support.lime-technology.com/forum/
#
# DISCLAIMER:
# Your use of this script is at your sole risk. This script is provided
#  "as -is", without any warranty
#
# Further, the authors of this script shall not be liable for any damages
# you may sustain by using this information, whether direct, indirect,
# special, incidental or consequential, even if they have been advised of
# the possibility of such damages.

# Define the following six values to setup this script

# The name of your SMTP server
sSmtpServer="smtp.myisp.com"
+ sSmtpServer=smtp.myisp.com

# Your domain name
sDomain="www.neo.rr.com"
+ sDomain=www.neo.rr.com

# The "from" email address
sMailFrom="[email protected]"
+ [email protected]

# The "to" mail address (The addressess must be separated by a space, a
# single address requires no spaces)
sRcptTo="[email protected]"
+ [email protected]

# The email subject
sSubject="unRaid Status Notification"
+ sSubject='unRaid Status Notification'

# Choose whether to include the contents of /proc/mdcmd in your status
# notifications (Setting this value to anything but "True" is the same
# as setting it to "False")
bIncludeMdcmd="True"
+ bIncludeMdcmd=True

# A copy of netcat (nc) is on the flash drive, add /boot/ to the PATH so it
# will be found when executed.
PATH=$PATH:/boot/
+ PATH=/usr/local/sbin:/usr/sbin:/sbin:./:/usr/local/bin:/usr/bin:/bin:/boot/

# initialize the error message to an empty string if no hourly OK message is desired
# like this:
#emsg=""
emsg=""
+ emsg=

# request that status be updated
echo "status" >/proc/mdcmd
+ echo status
# now check the status and report as needed
# Even if the contents of /proc/mdcmd are not normally included if all is OK,
# include it if something is wrong by setting the flag to True.
grep "mdState=STARTED" /proc/mdcmd >/dev/null 2>&1
+ grep mdState=STARTED /proc/mdcmd
if [ $? != 0 ]
then
        emsg="unRaid array not started"
        bIncludeMdcmd="True"
fi
+ '[' 1 '!=' 0 ']'
+ emsg='unRaid array not started'
+ bIncludeMdcmd=True

egrep "=DISK_INVALID|=DISK_DSBL" /proc/mdcmd >/dev/null 2>&1
+ egrep '=DISK_INVALID|=DISK_DSBL' /proc/mdcmd
if [ $? = 0 ]
then
        emsg="The unRaid array needs attention. One or more disks are disabled or invalid."
        bIncludeMdcmd="True"
fi
+ '[' 1 = 0 ']'

# RESYNC MESSAGES
P=${0##*/}              # basename of program
+ P=smtp_check_unraid.sh
R=${0%%$P}          # dirname of program
+ R=/boot/
P=${P%.*}              # strip off after last . character
+ P=smtp_check_unraid
export T=/tmp/${P}.$$
+ export T=/tmp/smtp_check_unraid.2174
+ T=/tmp/smtp_check_unraid.2174
trap "rm -f ${T}" EXIT HUP INT QUIT
+ trap 'rm -f /tmp/smtp_check_unraid.2174' EXIT HUP INT QUIT
strings < /proc/mdcmd > ${T}
+ strings
RESYNC=`egrep "^mdResync" ${T} | cut -d "=" -f2`
egrep "^mdResync" ${T} | cut -d "=" -f2
++ egrep '^mdResync' /tmp/smtp_check_unraid.2174
++ cut -d = -f2
+ RESYNC=0
if [ "$RESYNC" != "0" ]
then RESYNCPERCENT=`egrep "^mdResyncPrcnt" ${T} | cut -d "=" -f2`
     RESYNCFINISH=`egrep "^mdResyncFinish" ${T} | cut -d "=" -f2`
     RESYNCSPEED=`egrep "^mdResyncSpeed"  ${T} | cut -d "=" -f2`
     NL=`echo "\n"`
     sSubject="unRaid Resync Notification"
     emsg="The unRaid array is resync/rebuilding parity.${NL}${NL}"
     if [ ! -z "${RESYNCPERCENT}" ]
        then emsg="${emsg}Parity CHECK/RESYNC in progress, "
             emsg="${emsg} ${RESYNCPERCENT}% complete, "
             emsg="${emsg} est. finish in $RESYNCFINISH minutes."
             emsg="${emsg} Speed: ${RESYNCSPEED} kb/s."
     fi
     bIncludeMdcmd="False"
fi
+ '[' 0 '!=' 0 ']'

# if an error message was set, broadcast it to all the email addresses
# in the notify list
if [ "$emsg" != "" ]
then
        # look up the ip address given the machine name
        ip_addr=`net lookup $sSmtpServer 2>/dev/null`
        if [ $? = 0 ]
        then

        # Build the echo string
        sEcho="ehlo $sDomain\r\nmail from:$sMailFrom\r\n"

        # Add each recipient to the RCPT list
        for i in $sRcptTo
        do
                sEcho+="RCPT TO:"$i"\r\n"
        done

        # Message header
        sEcho+="data\r\nFrom:$sMailFrom\r\nTo:"

        # Add each recipient to the message header
        for i in $sRcptTo
        do
                sEcho+=$i";"
        done

        sEcho+="\r\n"

        # Message Subject
        sEcho+="Subject:$sSubject\r\n"

        # Message Body (You can change this to look how you want.  Just
        #              to include \r\n at the end of each line.)
        sEcho+="This message is a status update for unRAID  $HOSTNAME\r\n"
        sEcho+="-----------------------------------------------------------------\r\n"
        sEcho+="Server Name: $HOSTNAME\r\n"
        sEcho+="Server IP: `net lookup $HOSTNAME 2>/dev/null`\r\n"
        sEcho+="Status: $emsg\r\n"
        sEcho+="Date: "
        sEcho+=`date 2>/dev/null`
        sEcho+="\r\n"

        # Add the contents of /proc/mdcmd if elected by the user
        if [ "$bIncludeMdcmd" = "True" ]
        then
                sEcho+="\r\n"
                sEcho+="Output of /proc/mdcmd:\r\n"
                sEcho+="-----------------------------------------------------------------\r\n"

                # Add <CRLF> to each line
                file=/proc/mdcmd
                sEcho+=`sed "s/$/\\r\\n/" <$file`
                sEcho+="\r\n"
        fi
        # End the message
        sEcho+=".\r\n"
        sEcho+="QUIT\r\n"
        # Send the message we just built

        echo -e $sEcho|nc -i 1 -q 1 $ip_addr 25

        # Use the following line for debug
        #echo -e $sEcho|nc -w 1 -q 2 -i 1 -vv $ip_addr 25
        fi
fi
+ '[' 'unRaid array not started' '!=' '' ']'
net lookup $sSmtpServer 2>/dev/null
++ net lookup smtp.myisp.com
+ ip_addr=
+ '[' 255 = 0 ']'



rm -f /tmp/smtp_check_unraid.2174
+ rm -f /tmp/smtp_check_unraid.2174
root@Tower1:/boot#

 

Notice this portion:

 

+ '[' 'unRaid array not started' '!=' '' ']'
net lookup $sSmtpServer 2>/dev/null
++ net lookup smtp.myisp.com
+ ip_addr=
+ '[' 255 = 0 ']'

 

Link to comment

I am guessing that if you change this line:

sSmtpServer="smtp.myisp.com"

to

sSmtpServer="smtp-server.neo.rr.com"

 

It will work better.  Currently it is trying to look up the IP address of smtp.myisp.com.

 

net lookup is working now that you have the nameserver defined.  You just need to edit the smtp_check_unraid.sh script a tiny bit more to add the real smtp-server.

 

Joe L.

Link to comment

Wow!  How stupid of me.  I've changed that file so many times today I guess I forgot that one.

 

EDIT: Of course that worked.  I'm sorry for wasting your time with my stupidity.

Very happy to hear it works... 

Thanks for supplying the trace of the execution.  It really helps to figure out what is going on.

 

Joe L.

Link to comment
  • 3 weeks later...

Wow Joe L.  I'm sorry I haven't been able to help you troubleshoot all of these issues, but it looks like you've been taking care of business!  I don't know where you find the time and determination, but it's impressive  :).

 

I'm glad so many people have found this script useful.  The first version I posted has been running nonstop on my own Unraid server for over a year straight!

Link to comment
  • 3 years later...

I have followed this thread and succeeded in getting the smtp_check script to run via cron and to email me on a 4.7 final installation. However there are two minor points I would like to resolve:

 

1. The output from /proc/mdcmd includes the LAN ip address of the unRaid server. In my case this shows as 127.0.0.0, not as the actual ip. I haven't experienced problems accessing the unRaid server by name or ip from the windows machines on the network but I would be pleased if anyone could suggest how I might fix this issue. (a net lookup <servername> at the command line still returns 127.0.0.0). I have a dynamic ip set for the server at the moment.

 

2. I have been unable to get the script to reliably produce output where each name/value pair is on its own line in the email. Instead the output of /proc/mdcmd is in one continuous block. I have tried the variants on the original script posted in this thread, but none seem to work reliably.

I do have a work around for the problem (if I send to a Gmail account and forward to the account I want to receive at, the lf/cr's are preserved at the final destination - this suggests the script is working, but not in a way suitable for all email providers). Ideally I would have liked to send direct to the desired account.

Does anyone have any thoughts on what I might do to correct the issue?

 

 

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.