Mail file size of newest file in directory

I have been a long time lurker, and have learned a lot from these forums, thank you to everyone.

I am using Zoneminder to record a security camera feed. No motion detection, just 24 hour recording. I then have a script that checks Mysql for events dated the day before, and throws them at ffmpeg which turns them into a daily video. I never watch the video, so I am looking to find a way to make sure everything is running right. The daily video that is created is always about 600MB.

So I think there is 2 ways to go about this. Add a line at the end of my script that sends a mail with the created file's details, or run a separate script that checks a directory and mails the details of the newest file in that directory.

Anyone have any advice?
Thanks.

Here is the script I use:

#!/bin/bash
MUSER="XXXX"
MPASS="XXXXXX"
MHOST="localhost"
MDB="zm"
#MYSQL="$(which mysql)"
MYSQL="/usr/bin/mysql"
#MYSQLDUMP="$(which mysqldump)"
MYSQLDUMP="/usr/bin/mysqldump"
PATHTOEVENTS="/var/cache/zoneminder/events"
MonitorId="$1"
tmpdir="/tmp"

if [ "$1" == "$null" ]
  then
    echo You Must Specify The Monitor ID i.e \'$0 4\' would specify monitor id 4
    exit
fi

EVENTS="$($MYSQL -D$MDB -u$MUSER -p$MPASS -Bse 'select id from Events WHERE (StartTime BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 1 DAY ) AND CURDATE( )) AND (MonitorId = '$MonitorId') order by id asc')"
mkdir $tmpdir/$MonitorId
x=1
for event in ${EVENTS[@]}
do
        if [ $x -eq 1 ]
          then
            mysqldate="$($MYSQL -D$MDB -u$MUSER -p$MPASS -Bse 'select StartTime from Events WHERE id = '$event'')"
            date=`date +%Y_%m_%d --date="$mysqldate"`
            firstevent="$event"
            echo Making Images and Placing them in $tmpdir/$MonitorId .... Please Be Patient this could take a while.
        fi
          for i in $(ls -r -t $PATHTOEVENTS/$MonitorId/$event/*jpg)
          do counter=$(printf %06d $x)
            ln -s "$i" $tmpdir/$MonitorId/img"$counter".jpg
            x=$(($x+1))
          done
done

/usr/bin/ffmpeg -f image2 -i $tmpdir/$MonitorId/img%06d.jpg -vcodec libx264 -vpre normal -threads 0 /home/sasaki/camera_videos/$date-Data_Center.mp4 

rm -rf $tmpdir/$MonitorId

I would recommend writing a video file knowledgable app that divides the file without losing any frames; in fact, duplicating the end of one on the next would be great. Smaller files means you can spot check them, like 5 seconds of each 20 minutes.

Command ls will tell you how long a file currently is, fuser will tell you pids if it is open (locally), and ps -fp "$pids" will tell you what runs on those pids.

Not sure about the rest of the stuff, but if your just trying to grab the file size of the most recent file in a directory:

fsVar=$(ls -lthr | tail -1 | awk '{print $5}')
echo "Body of e-mail $fsVar" | mailx -s "Subject of e-mail" user@domain.com -f no-reply@domain.com

This will send the size of the file, you can remove the h if you don't want it in human readable format.You can alwo remove the awk line if you want all details, including date, permissions, name, etc...

Edit: The above assumes your running the script in the directory the files are in. If they aren't, just add the path after ls -ltrh

DGPickett - When I put the system together, I was using shorter videos, but it got to hard to catalog and keep track of them. We are keeping them for 3 years, so we decided to go with one a day. But thanx for the ideas.

cbo0485 - That is exactly what I needed. I didn't have mailx so I changed the mail part a little, and added the video title (which contains the date) to the body of the mail.

Thank you for you speedy and informative responses!

zip is a nice way to package all videos for a time period. Internal relative paths allow you to pull out a subset by wildcard. You can list the set with one unzip and for each, use another unzip to extract to stdout for playing from the pipe or temp file.