Sponsored Content
Top Forums Shell Programming and Scripting Mail file size of newest file in directory Post 302495559 by iamVERYhungry on Thursday 10th of February 2011 02:35:32 PM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
shells(4)							   File Formats 							 shells(4)

NAME
shells - shell database SYNOPSIS
/etc/shells DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser- shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root. A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines which search the file. Blank lines are also ignored. The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/ksh93, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/ksh93, /usr/bin/pfcsh, /usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh, and /usr/sfw/bin/zsh. /etc/shells overrides the default list. Invalid shells in /etc/shells could cause unexpected behavior, such as being unable to log in by way of ftp(1). FILES
/etc/shells list of shells on system SEE ALSO
vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4) SunOS 5.11 20 Nov 2007 shells(4)
All times are GMT -4. The time now is 07:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy