I have writen the code below and would like to automate it so I have aded a line to crontab.
Code: Select all
## this file is being ran from the directory on the HDD '/CCTV/RearOfHouse/' (which is connected to the pi)
# create an array with all the files/dir inside ~/CCTV/RearOfHouse/
#!/bin/bash
arr=(~/CCTV/RearOfHouse/*.mp4)
# iterate through array using a counter
for ((i=0; i<${#arr[@]}; i++)); do
################### SET UP VARIABLES FOR CODE ###########################
j=${arr[$i]:30:6}"_mp4" ## 201903_mp4
k=${arr[$i]:0:27}"mp4Files/" ## /home/pi/CCTV/RearOfHouse/mp4Files/
h=${arr[$i]:0:48} ## /home/pi/CCTV/RearOfHouse/ARC20190315080521.mp4
m=${arr[$i]:0:48} ##/home/pi/CCTV/RearOfHouse/ARC20190315080521.mp4
n=${k}${j} ## /home/pi/CCTV/RearOfHouse/201903
o=${arr[$i]:30:6} ## 201903
oo="${k}${o}""_mp4"
}
l="${k}${j}"
}
################### CREATE ANY NEW DIRECTORIES THAT NEED CREATING ##############
mkdir -p "${oo}" ### this creates new directories in location of this exec file
################# MOVE ALL FILES INTO RELEVANT DIRECTORIES NEXT ##################
### mv pathtofileA pathtofileB ###
aa="201901_mp4"
bb="201902_mp4"
cc="201903_mp4"
dd="201904_mp4"
ee="201905_mp4"
ff="201906_mp4"
gg="201907_mp4"
hh="201908_mp4"
ii="201909_mp4"
jj="201910_mp4"
kk="201911_mp4"
ll="201912_mp4"
if [ ${j} = ${aa} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${bb} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${cc} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${dd} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${ee} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${ff} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${gg} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${hh} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${ii} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${jj} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${kk} ]; then
mv "${m}" "${l}"
fi
if [ ${j} = ${ll} ]; then
mv "${m}" "${l}"
fi
done
################# ABOVE OUTPUTS HAVE CREATED DIRS AND PUT FILES IN THEM ################
If I run the command :-
pi@raspberrypi:~/CCTV/FrontOfHouse $ ./Createmp4Dirs.sh
Everything runs fine, directories are created and the relevant files are put into them.
I have added the the following line to my crontab file:-
20 * * * * source /home/pi/CCTV/FrontOfHouse/ .CreatejpgDirs.sh
but it does not run this line?
I log in as pi, and have created the crontab from the 'pi@raspberrypi:~' using 'crontab -e'
Can anyone tell me why it is not running and how to fix it please, as my files build up in the base directories very fast and searching for a particular file becomes problematic.
Thanks