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-chaning 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 -t cifs //192.168.178.xxx/PATH/ /media/nasdir/
Make sure you can access it and that you can see files. If you already have files at “//192.168.178.xxx/PATH/” you can use
ls -al /media/nasdir/
Also create a file with
touch /media/nasdir/test
and check if it has been created.

#!/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…)

linux/raspberry/picam/scripts/copyjob.1433508849.txt.gz · Last modified: 2017/03/01 12:50 (external edit)