Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
motion bash script for cron.weekly - moves files into separated by month and week folders
#!/bin/sh
#cron weekly
DateMonth=$(date +'%b') #Monthly variable
MotionPath="/var/motion/"
DateWeek=$(date +'%W')
DateWeek=$((DateWeek - 1))
Mfolder=$MotionPath$DateMonth
Wfolder=$Mfolder/$DateWeek
DataStamp=$(eval date +%j)
create_dir_month()
{
if [ -d $Mfolder ]; then
echo "Got $Mfolder directory";
else
echo "Creating $Mfolder dir "
mkdir $Mfolder
fi
}
create_dir_week()
{
if [ -d $Wfolder ]; then
echo "Got $Wfolder directory";
else
echo "Creating $Wfolder dir "
mkdir $Wfolder
fi
}
copy_aj_files()
{
mv $MotionPath/*.avi -t $Wfolder
mv $MotionPath/*.jpg -t $Wfolder
cp $MotionPath/*.php -t $Wfolder
echo "day $DataStamp moved Motion files into subdir $Wfolder"
}
create_dir_month
create_dir_week
copy_aj_files
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.