I needed to get alarm images remotely so created the script below. There must have been several methods of emailing images posted already but here is mine:
Notes:
* I could not get sendmail working sufficiently well through my ISP so used a perl script I found on the net called "sendEmail".
* I added a column (Emailed) to the table "Frames" to make doubly sure I would not get caught in email loop (prob not needed at all).
* I have a web site so used that as the destination of the email.
* Selected the two top MaxScore frames via sql SORT and LIMIT to send.
* Zeroed MaxScore in table "Events" so filter would not be triggered again.
* I have only rudimentary knowledge in scripting so would be interested in improvements.
1. Create a filter based on MaxScore (mine is > 5) and set to execute a script (Alarm1)
2. My script:
Images=$2 # Parm $1 is a value I pass from the script (unused)
EventId=`basename Images`
TempFile="/tmp/SqlOut"
echo "SELECT FrameId from Frames" > /tmp/SqlIn.sql
echo "WHERE EventId=$EventId AND Emailed=1" >> /tmp/SqlIn.sql
echo "ORDER By Score DESC limit 0,2;" >> /tmp/SqlIn.sql
echo "UPDATE Frames SET Emailed=0 " >> /tmp/SqlIn.sql
echo "WHERE EventId=$EventId;" >> /tmp/SqlIn.sql
echo UPDATE Events Set MaxScore=0 " >> /tmp/SqlIn.sql
echo WHERE Id=$EventId;" >> /tmp/Sqlin.sql
# Execute the sql
mysql --user=<your user> --password=<your pass> zm > $TempFile \
< /tmp/SqlIn.sql
# Read the sql results
exec<$TempFile
read line # Get past the column id
while read Line
do
Len=`expr length $line`
if [ $Len -eq 2 ]
then
File="0"$Line"-capture.jpg"
else
File=$Line"-capture.jpg"
fi
# Send the results
MailLine="sendEmail -f <a source email adr> -t <destination email> -s <email server adr> -m <your message here> -u Motion Detected -a $Images/$File"
$MailLine
done
Chuck
It "seems" to work just fine.