Created
September 5, 2015 14:20
-
-
Save bytepossum/12d7eb59db8f19d8524c to your computer and use it in GitHub Desktop.
Bash script for cron to check if motion is running and free disk space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SERVICE='motion' | |
RUN_COMMAND='nice -n 10 /usr/local/bin/motion &' | |
LOGFILE=/home/pi/motion/motion.log | |
VOPATH=/media/data/motion # video output directory | |
LIMIT=90 # maximum disk usage | |
if [ ! $(pidof $SERVICE) ] | |
then | |
# process not running, starting | |
echo "[!!!] [$(date +%c)] check_motion.sh - $SERVICE is not running, starting '$RUN_COMMAND'" >> $LOGFILE | |
$($RUN_COMMAND) | |
fi | |
if [ $(df -P $VOPATH | awk '{ gsub("%",""); capacity = $5 }; END { print capacity }') -gt $LIMIT ]; then | |
echo "Free space is less than $LIMIT, removing 10 oldest files." | |
cd $VOPATH | |
rm $(ls -tr | awk 'NR<10') | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment