This is an old revision of the document!
This script copies all your .jpg and .avi captures to a mounted NAS. Before it does so, it will check if there is a directory with the date of today. If it doesnt exist it will create one with the subdirectories “Videos” and “Pictures”. After that it copies the files to a non-changing local directory and then from there to the created directories on your NAS. The script can be executed via crontab.
First mount your NAS.
Mount networkshares
Second create a file named “copyjob.sh” with the code below
#!/bin/bash DATE=`date +%d_%m_%Y` BASEPATH=/records/ COPYPATH=/records/copy/ NETPATH=/media/nasdir/ if [ ! -d "$NETPATH$DATE" ]; then mkdir $NETPATH$DATE mkdir $NETPATH$DATE/Videos mkdir $NETPATH$DATE/Pictures fi NETPATHAVI=$NETPATH$DATE/Videos NETPATHJPG=$NETPATH$DATE/Pictures mv $BASEPATH*.avi $COPYPATH sleep 10 mv $BASEPATH*.jpg $COPYPATH sleep 10 mv $COPYPATH*.avi $NETPATHAVI sleep 10 mv $COPYPATH*.jpg $NETPATHJPG sleep 10
Make sure you use
chmod +x cronjob.shto make it executeable.
vi /etc/crontab
0 * * * * /records/copyjob.sh >/dev/null 2>&1The job will be executed everytime the clock hits 0 minutes (for example 1:00pm 2.00am…)
Discussion