Site Tools


linux:raspberry:picam:scripts:copyjob

This is an old revision of the document!


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 cronjob.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 \;



linux/raspberry/picam/scripts/copyjob.1511971180.txt.gz · Last modified: 2017/11/29 16:59 by lunetikk