Motion - Daily File Store Script

Daily File Store Shell Script


Simple shell scripts that store pictures into folders every day and clean it up later on if you wish.

Detailed Description

This is my script that is called from cron at one minute before midnight with a cron line like this:

59 23 * * * /root/ >/dev/null 2>&1

The first script is called "", don't forget to set it's permissions to 755 (use chmod 755).

The other script below is called "", you can use it if you like, it's called at the end of the other script and will delete all old files and remove the directory, SO BE CAREFUL TO GET THIS ONE RIGHT. You don't have to use this, but it's nice to clean up all those old files. It has handled days with 40,000 files with my setup.

My setup stores the pictures at "/root/pic-link", you need to change this to what your setup has. In my case "pic-link" is a symbolic link to a /home directory I use to store pictures because the /home directory is the largest directory. You may run out of room if you just use the root directory (I operate everything root on my home remote system on my private internal network, it's up to you).

The number in the script below, "7776000" is 90 days in seconds, you can change that to how old the directories should be to be removed.

The script below is the one called "":

#! /bin/sh

# at midnight we move everything into it's own dated directory

TEMP=`date +%F`

cd /root/pic-link
mkdir $TEMP

ls -1 | grep jpg | xargs -n 10 -i mv {} $TEMP/
rm -f $TEMP/lastsnap.jpg

cd /root

# now remove old directories and files


The script below is the one called "":

#! /bin/sh

cd /root/pic-link

for i in *

if [ -d $i ]
TODAY=`date +%s`
FILETIME=`date +%s -d $i`

if [ $? -eq 0 ]

if [ $DIFF -gt 7776000 ]
echo $i $DIFF "more than 90 days, say bye bye"
cd $i
# remove a lot of files, then remove dir
ls -1 | xargs -n 10 -i rm -f {}
cd ..
rmdir $i
echo $i $DIFF "OK"

echo $i "is not a dated directory"


Comments and Bug Reports

RelatedProjectsForm edit

ProjectSummary Simple shell scripts that store pictures into folders every day and clean it up later on
ProjectStatus Alpha
ReleaseVersion 1
ProjectSubmitter Anon Dude
Topic revision: r2 - 21 Dec 2005, KennethLavrsen
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Please do not email Kenneth for support questions (read why). Use the Support Requests page or join the Mailing List.
This website only use harmless session cookies. See Cookie Policy for details. By using this website you accept the use of these cookies.