Wow

"Sticky" status ! Thanks, SiteAdmins.
Update
22Sep2008 Version 1.1: Ok ... here's a more sophisticated version (able to send an email if TEMP on Disk hits or exceeds a threshhold). Runs continously until user aborts it. ***READ DOCUMENTATION*** at beginning (about 30 lines, including where you customize to your setup), and at the end (mostly hints about "sendmail"). The way it is written "SENDMAIL" is DISABLED. You can enable by removing the hash-mark (Section L) after you're sure it will work in your environment.
Update
29Sep2008 Version 1.2: Fixed some minor issues. Added CatNap to reduce reporting time since last available update. (This version should soon appear on Eden's site.)
( I wish I could figure out how to paste this code with the tab-stops properly aligning the code ... oh well

)
ENJOY !

Georg
Code:
#!/bin/sh
# ------------------------------------------------------------------------------
# NASLite Disk Monitor: A script to report Disk-# status on NASLite server.
# Extracts the useful info from NASLite's "storage.htm" file.
# Semi-intelligent ... but not all possible conditions fully tested (for
# example: S.M.A.R.T. turned off or unavailable, or Update turned off, etc).
# Also, if temporary files exist, and this script is run with different
# users permission problems may prevent a clean "rm" of old files.
# Can send WARNING EMAIL if temperature threshhold is reached/exceeded.
# But ***NOTE*** that "sendmail" is **TURNED OFF** by default.
# Remaining known issue: if local & NL time are not sync'ed.
# Refer to more documentation at end of this script.
# ------------------------------------------------------------------------------
# By Georg for NASLite Forum Community; tested on "NASLite-2 USB v2.06 08-2007"
# ------------------------------------------------------------------------------
# Version Info/Change History:
# 0.1 never released.
# 1.0 released 20Sep2008 (still did not contain this version info block)
# Added automatic determination of NumDisks.
# 1.1 released 22Sep2008 Added Section lettering. Added Section E: "Figure
# out interval" and continous While/Do Loop (Section F+); The
# reports in the loop are placed in a cumulative "LOG".
# Added "sendmail" capability.
# 1.2 released 29Sep2008 Added "$CatNap" (more real-time) Section E.1.
# Fixed bug in Section F & adjust Section K (case of TEMP is DISABLED).
# Fixed problem if NL server is not running (!) (Section C.1).
# ------------------------------------------------------------------------------
Version="1.2"
# ------------------------------------------------------------------------------
# SECTION A: User MUST ADJUST VARIABLES in this section, especially first 4.
# ------------------------------------------------------------------------------
NL_IP="192.168.1.XXX" # Use *YOUR* NASLite server IP address here.
TEMP_WARN=38 # Your DISK TEMP THRESHOLD WARNING LEVEL.
Recipient="xxx@yyy.zzz" # Use *YOUR* email address.
NL_LOG="/home/shared/NL_" # Use *YOUR* prefered LOG FILE name/location.
NL_Data_Folder="/usr/tmp" # Use *YOUR* prefered location for temp files.
# ------------------------------------------------------------------------------
# SECTION B: Below are additional variables/parameters.
# ------------------------------------------------------------------------------
NL_LOG=$NL_LOG`date +%Y%m%d%H%M`".log" # Append time-stamp & LOG extension.
HDINFO="storage.htm"
Report="NL_DisksStatus.txt"
WarnMail="MailWarning.txt"
WARN_MSG1="******* WARNING *******"
WARN_MSG2=" AT or EXCEEDING THRESHOLD of $TEMP_WARN"
Title="----- NASLite Disk Monitor version $Version. ------ IP=$NL_IP"
ERR_MSG1="Unable to retrieve HTML from NL Server."
ERR_MSG2="$0 terminated ... "
# ------------------------------------------------------------------------------
# SECTION C: Get HTM file into local folder. "wget" may require ftp services ??
# Version 1.2: Added file cleanup -- permission problems if run from different
# user accounts.
# ------------------------------------------------------------------------------
rm -f disks?.txt $Report $WarnMail 2> /dev/null
cd $NL_Data_Folder
rm -f $HDINFO 2> /dev/null
wget http://$NL_IP/Status/htm/$HDINFO 2> /dev/null
# ------------------------------------------------------------------------------
# SECTION C.1: Make sure wget is successful.
# ------------------------------------------------------------------------------
echo $Title | sed 's/$/\r/' > $NL_LOG
if [ ! -f $HDINFO ] ; then
echo $ERR_MSG1 >> $NL_LOG
echo $ERR_MSG2 >> $NL_LOG
echo $ERR_MSG1
echo $ERR_MSG2
exit 1 ;
fi
# ------------------------------------------------------------------------------
# SECTION D: Figure out how many disks are listed ... and set NumDisks.
# Assumption: There's one "Disk-" line for each disk.
# ------------------------------------------------------------------------------
NumDisks=`cat $HDINFO | grep -i "Disk-" | wc -l`
# ------------------------------------------------------------------------------
# SECTION E: Figure out interval.
# Possibilities: 01, 05, 10, 15, 30, 45, 1h, 4h, 8h, --
# So far only tested 15 & 5 minute & 1h intervals ...
# ------------------------------------------------------------------------------
#
UpdateMSG=`cat $HDINFO | grep -i "Content updated every"`
Interval=`echo $UpdateMSG | sed -e 's/<[^>]*>//g' | cut "-d " -f7`
Units=`echo $UpdateMSG | sed -e 's/<[^>]*>//g' | cut "-d " -f8 | cut -d. -f1`
echo -n "Update Interval is" $Interval $Units
if [ $Units == "min" ] ; then
Mult=60 ;
else
Mult=3600 ;
fi
Rest=`/usr/bin/expr $Mult \* $Interval `
echo " == Sleep Time of" $Rest "seconds."
# ------------------------------------------------------------------------------
# SECTION E.1: For first $Rest SLEEP, reduce to $CatNap.
# Reason: If Update $Interval is very long, and the program was started close
# to the NEXT update, then a large amount of SLEEP is wasted until the
# actual delayed reporting for that soon-to-occur update with its second set
# of data. Calculate the shortened time to next update+2mins as $CatNap.
# Problem = if this system & NASLite system are not synchronized !!!
# ------------------------------------------------------------------------------
#
LastUpdat=`cat $HDINFO | grep -i "Last update" | cut -d. -f3`
TLastStr=`echo $LastUpdat | sed -e 's/<[^>]*>//g' | cut -c12-`
TLast=`date -u --date="$TLastStr" +%s` # Secs since 1970 (%s option).
TNow=`date -u +%s` # Secs since 1970 (%s option).
Tdiff=`expr $TNow \- $TLast` # Secs since last update.
T2Next=`expr $Rest \- $Tdiff` # Secs to NEXT update.
CatNap=`expr $T2Next \+ 120` # Will never be ZERO ... use it once!
echo "First time take shorter CatNap of $CatNap (instead of $Rest) seconds."
# ------------------------------------------------------------------------------
# ******************************************************************************
# MAIN LOOP: Run continously ... report each $Interval. Email if Alarm.
# ******************************************************************************
# ------------------------------------------------------------------------------
while [ "1" == "1" ] ; do
# ------------------------------------------------------------------------------
# SECTION F: Create a table header, extract "Last update" and NumDisks info.
# Assumption: There's one "TEMP" line for each disk.
# Bug or Problem: if S.M.A.R.T. is UNAVAILABLE or DISABLED.
# ------------------------------------------------------------------------------
NumTemps=`cat $HDINFO | grep -i temp | wc -l`
echo -n " Disk# Size Used Free " > disks1.txt
cat $HDINFO | grep -i update | cut -d. -f3 >> disks1.txt
#BUG: ##cat storage.htm | grep -i temp | tail -$NumDisks >> disks1.txt
cat $HDINFO | grep -i "Disk-" | tail -$NumDisks >> disks1.txt
# ------------------------------------------------------------------------------
# SECTION G: Remove bulk of the html code; then clean up some left-over special
# html formatting. **NOTE** very specific to the html code implemented
# in whatever current NL version. If more commands needed, continue incementing
# '#' in "disks#.txt", then in next section copy final txt file to $Report.
# ------------------------------------------------------------------------------
sed -e 's/<[^>]*>//g' disks1.txt > disks2.txt
sed -e 's/\ / /g' disks2.txt > disks3.txt
sed -e 's/CUSED/C Used/g' disks3.txt > disks4.txt
sed -e 's/READ ONLY /\t/g' disks4.txt > disks5.txt
sed -e 's/READ\/WRITE /\t/g' disks5.txt > disks6.txt
sed -e 's/\°/ /g' disks6.txt > disks7.txt
# ------------------------------------------------------------------------------
# SECTION H: Copy final txt file to $Report (for later ease of use).
# Convert UNIX EOL char. to DOS equivalent.
# Append current status report to cumulative NL_LOG file.
# ------------------------------------------------------------------------------
cat disks7.txt > $Report
sed 's/$/\r/' $Report >> $NL_LOG
# ------------------------------------------------------------------------------
# SECTION I: Display $Report.
# ------------------------------------------------------------------------------
echo "Local time is" `date`
cat $Report
# ------------------------------------------------------------------------------
# Now lets put some REAL INTELLIGENCE here ... TEMPs are known, could, for
# example, send email in case a THRESH-HOLD TEMP is EXCEEDED ...
# ------------------------------------------------------------------------------
# SECTION J: First, extract TEMPS into a single word list.
# ------------------------------------------------------------------------------
Result=`sed 's/ [ ]*/ /g' $Report | cut "-d " -f 2,7 | tail -$NumDisks`
# ------------------------------------------------------------------------------
# SECTION K: Now scan the list of results (word-pairs DiskName/TEMP).
# ------------------------------------------------------------------------------
Alarm=0 # RESET TEMPerature Alarm to OFF.
toggle=0
for WORD in $Result ; do
toggle=`expr 1 - $toggle` # Toggle flag so that words in
if [ $toggle -eq 1 ] ; then # $Result can be handled in pairs.
DISK=$WORD # Get DiskName (=1st) field in $Result.
continue ; # Skip to second field.
else
TEMP=$WORD # Get TEMP (=2nd) field in $Result.
# Ensure that $TEMP is numeric (NOT Alpha as in "DISABLED")
# before testing its numeric value against threshhold.
Alpha=`echo $TEMP | sed 's/[0-9]//g'`
if [ -z $Alpha ] ; then
if [ $TEMP -ge $TEMP_WARN ] ; then
echo "$WARN_MSG1" $DISK at $TEMP "$WARN_MSG2"
echo -n "$WARN_MSG1" $DISK at $TEMP >> $NL_LOG
echo "$WARN_MSG2" | sed 's/$/\r/' >> $NL_LOG
Alarm=1 # Trigger the Alarm.
ListEnd=1 ;
else
###echo $DISK is at $TEMP degrees C
ListEnd=1 ;
fi
ListEnd=1 ;
fi
ListEnd=1 ;
fi
ListEnd=1 ;
done
# ------------------------------------------------------------------------------
# SECTION L: Send WARNING EMAIL ...
# (Obviously requires a "sendmail" mail server running on local system.)
# ------------------------------------------------------------------------------
if [ $Alarm -eq 1 ] ; then
domain=`echo $Recipient | cut -d@ -f2`
echo "Date: `date`" >> MailMsg
echo "From: no-reply@$domain" > MailMsg
echo "Subject: NL TEMP WARNING" >> MailMsg
echo "To: $Recipient" >> MailMsg
echo '' >> MailMsg
echo -n "$WARN_MSG1" >> MailMsg
echo At least one disk "$WARN_MSG2" >> MailMsg
echo '' >> MailMsg
echo "----------- Full Report is ------------" >> MailMsg
cat $Report >> MailMsg
sed 's/$/\r/' MailMsg > $WarnMail
# ----------------------------------------------------------------------
# NOTE: Actual emailing is currently ***DISABLED***
# EN-ABLE 'sendmail' by REMOVING the '#' in front of it.
# Using "-f" so "Return-Path" won't be "root" or other unusual user.
# ----------------------------------------------------------------------
rm -f MailMsg 2> /dev/null
###/usr/sbin/sendmail -fDoNotReply -t < $WarnMail
ListEnd=1 ;
fi
# ------------------------------------------------------------------------------
# SECTION M: SLEEP until next Interval; then grab updated HTM, and loop around.
# Updated after Section E.1 was added with $CatNap.
# ------------------------------------------------------------------------------
rm -f $HDINFO 2> /dev/null
if [ $CatNap -gt 0 ] ; then
sleep $CatNap
CatNap=0 # Reset so it's used only once.
ListEnd=1 ;
else
sleep $Rest
ListEnd=1 ;
fi
wget http://$NL_IP/Status/htm/$HDINFO 2> /dev/null
ListEnd=1 ;
# ------------------------------------------------------------------------------
done # END of continuous WHILE LOOP
# ------------------------------------------------------------------------------
exit 0 # Clean non-error exit if this point is reached.
# ------------------------------------------------------------------------------
# Regarding "SENDMAIL":
# This script uses "sendmail" at bottom of Section L. Obviously the CPU this
# script runs on must contain a properly set up mechanism for sending mail.
# For most users this may have already been arranged, but if not, is not a
# trivial excercise. In particular Section L assumes that (for example) the
# user running this script (may be 'root' because the script is part of the
# startup sequence) is not necessarily properly authenticated, and since
# an ISP may require that mail headers match a certain domain the "Return-Path"
# is set to the domain of the recipient ... etc etc. The file "main.cf" in
# "/etc/postfix" may also require adjustments.
#
# I have been testing this script using the "root" login on a server running
# Linux. The server does not run an email program ... email is done at
# the WinXP clients, and therefore user accounts on the server do NOT correlate
# to ISP account (and their email addresses). For testing I temporarily set
# up SMTP on the server.
#
# So ... the general comments is **** USER BEWARE ***. For "sendmail" to
# properly work the user may have to do his/her own investigation.
# ------------------------------------------------------------------------------
# Regarding "ListEnd=1 ;"
# I don't like how "/bin/sh" uses the ";" to terminate the "list" of commands
# to execute in an "if" or "while" statement. I use a (dummy) separate line
# to designate a more obvious last statement for the section in question.
# Non-standard -- I know -- apologies to hot-shot programmers (which I am not).
# ------------------------------------------------------------------------------
# Can add a line to "/etc/rc.local" to start this script on boot. However,
# a couple of things to watch: 1] make sure to start it with a "/bin/sh" shell,
# and 2] route 1> and 2> to some specific desired location , and 3] use "&".
# Here's an example: (where xxx is name you give this script, "NL_HD_Stat.sh")
# /bin/sh ~/bin/xxx 1> /usr/temp/xxx_out.txt 2> /usr/temp/xxx_err.txt &
# ------------------------------------------------------------------------------
# Other "to-do":
# Consider allowing command line options to designate the $Recipient,
# the loop count, the $TEMP_WARN threshhold, etc.
# Fix problem of de-synced clocks of NL & this system running script (de-sync
# messes up the SLEEP/CatNap intervals), which can waste a lot of time between
# current TEMPs and last status if the Update interval is long.
# Fix "permission denied" errors if temp files exist and can not be removed
# by the user currently running the script.
# Add general clean ERROR control (ON ERROR perform some action).
# ------------------------------------------------------------------------------