Site Tools


linux:raspberry:picam:scripts:copyjob

Copyjob

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 copyjob.sh
to make it executeable.
Create a cronjob for it by inserting the following line to the end in
 vi /etc/crontab
0 * * * * /records/copyjob.sh >/dev/null 2>&1
The job will be executed everytime the clock hits 0 minutes (for example 1:00pm 2.00am…)

Troubleshooting

If the copyjob fails because of “too many arguments” its because mv *.jpg extends that command to mv blabla.jpg xyz.jpg etc… Too many files then cause that error because the command is too long. Instead of the mv command above in the script you can use

find $BASEPATH -name ".jpg" -exec mv {} $NETPATHJPG \;

Like this:

find $BASEPATH -name ".avi" -exec mv {} $COPYPATH \;
sleep 10
find $BASEPATH -name ".jpg" -exec mv {} $COPYPATH \;
sleep 10
 
find $COPYPATH -name ".avi" -exec mv {} $NETPATHAVI \;
sleep 10
find $COPYPATH -name ".jpg" -exec mv {} $NETPATHJPG \;
sleep 10



linux/raspberry/picam/scripts/copyjob.txt · Last modified: 2019/01/09 18:53 by lunetikk