Mail file size of newest file in directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mail file size of newest file in directory
# 1  
Old 02-10-2011
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:

Code:
#!/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

# 2  
Old 02-10-2011
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.
# 3  
Old 02-10-2011
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:

Code:
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
# 4  
Old 02-11-2011
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!
# 5  
Old 02-11-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Size of a directory or a file

Hello, Here is my code: :~$ truncate -s 16M MyTestFile.txt :~$ du -h MyTestFile.txt 4,0K MyTestFile.txt Q1: Please why du -h does not work in this case ? Q2: Other than "du -h", how can i get the size of a directory (using linux command) Thanks a lot. Best Regards. (2 Replies)
Discussion started by: chercheur111
2 Replies

2. UNIX for Dummies Questions & Answers

Check file size and mail

Hi, I am trying to write a script which will check if the filesize is grather than 0 KB, compress the file and send to the email list else if the file size is zero KB don't send a mail update the log if then echo "Validate the file" | mailx -s " There are errors : " ${EMAIL_LIST} else... (5 Replies)
Discussion started by: mora
5 Replies

3. UNIX for Dummies Questions & Answers

Mailx - temporary mail message file: No such file or directory

How would I go about resolving this error temporary mail message file: No such file or directory Can anybody tell me where the default location is for the temporary mail message file is for mailx? It appears that it doesn't exist. Thanks (1 Reply)
Discussion started by: joen
1 Replies

4. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

5. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

6. Shell Programming and Scripting

Get the newest file in a directory.

I am new to shell scripting so i need some help need how to go about with this problem. I have a directory which contains files in the following format. The files are in a diretory called /incoming/external/data AA_20100806.dat AA_20100807.dat AA_20100808.dat ... (4 Replies)
Discussion started by: ziggy25
4 Replies

7. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

8. Shell Programming and Scripting

Size of file and directory

Hello. I do have a problem. The statement sounds like this: Given a directory, find all subdirectories (regardless of depth) which contain a file that has more than a half of the size of the respective subdirectory. I've tried to solve this in many ways, but all I came up with is half... (1 Reply)
Discussion started by: WorkOfArt
1 Replies

9. Shell Programming and Scripting

How to know size of file in a directory

Hi, I have to directory /usr/inbound ------------- 10900.txt 10889.txt 109290202.txt I need to create inbound directory and i need to know size of these files one by one if file size is zero i need to print message like "empty file" Please help me how to solve this thanks krish. (1 Reply)
Discussion started by: kittusri9
1 Replies

10. UNIX for Dummies Questions & Answers

Mail based on file size

Hi Friends, i am trying to write a shell script which will check for the logfile size. if the content of the logfile is wc -l >=1 then send mail with log file as attachment.else do nothing. i'm trying the below code can any one help on this if ] then (echo "`cat... (2 Replies)
Discussion started by: rajendragora
2 Replies
Login or Register to Ask a Question