Skip to content

Instantly share code, notes, and snippets.

@fawkesley
Last active January 24, 2018 16:19
Show Gist options
  • Save fawkesley/7eb6891f0e2674cfd45e01853def335e to your computer and use it in GitHub Desktop.
Save fawkesley/7eb6891f0e2674cfd45e01853def335e to your computer and use it in GitHub Desktop.
/etc/cron.hourly/organise-cctv on cctv-server
#!/bin/sh -eu
PATH=/bin:/usr/bin
DIR=/media/seagate_250gb/cameras/front
USER="camera-front"
cd_to_directory() {
cd "$DIR"
}
make_day_directories() {
DAY_DIRS="$(ls -al ${DIR}/snapshot_* |grep --only-matching -P '\d\d\d\d-\d\d-\d\d' |sort -u |xargs echo)"
for date in $DAY_DIRS; do
su ${USER} -c "mkdir -p $date"
done
}
rename_snapshots() {
su ${USER} -c "rename 's/snapshot_(\d\d\d\d-\d\d-\d\d)/\1\/snapshot/g' ${DIR}/snapshot_*.jpg"
}
rename_motion() {
su ${USER} -c "rename 's/motion_(\d\d\d\d-\d\d-\d\d)/\1\/motion/g' ${DIR}/motion_*.*"
}
delete_old_files() {
find $DIR -type f -mtime +30 -exec su ${USER} -c "rm {}" \;
}
delete_tmp_files() {
find $DIR -type f -iname "*.thm.tmp" -mtime +1 -exec su ${USER} -c "rm {}" \;
}
cd_to_directory
make_day_directories
rename_snapshots
rename_motion
delete_old_files
delete_tmp_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment