doubleudee1 wrote: ↑Sun Mar 17, 2019 9:45 am
Andyroo wrote: ↑Sat Mar 16, 2019 5:31 pm
Something like this will create the directory in the format YYYYMM (not tested on a Pi - only Pi Desktop emulated under Fusion):
Code: Select all
year=${file:3:4}
month=${file:7:2}
filedate=${year}${month}
mkdir -p ${filedate}
This will return the current date in YYYYMM (I have assumed you are using the UK locale for this - check first):
Code: Select all
todayyr=$( date +"%Y")
todaymth=$( date+"%m")
today=${today}${todaymn}
Then a check to see if the file date is less than today:
Code: Select all
if [ $[filedate -lt today ]
mv $file.mp4 $filedate
mv $file.jpg $filedate
fi
Notes:
I assume the file
name is in the variable ${file}
The file(s) is in the current directory
The archive directory are directly below the current directory
I create the directory in YYYYMM format as this sorts and compares better - old old trick from an old pgmr
I cheat and use the '-p' option in mkdir as it does not return an error if it already exists
Its waffle code and can be shortened but this way you can try each line rather than one big long command
Nothing like being standard - Uppercase 'Y' for year in numeric and lowercase 'm' for month
This is what I have come up with from your code (about to try it today) I have put it in a crontab file.
########################################
10 10 * * * find /CCTV/RearOfHouse/ -type file year=$(file:3:4) month=$(file:7::2) filedate=$(year)&(month) mkdir -p $(filedate)
todayyr=$( date +"%Y")
todaymth=$( date+"%m")
today=${today}${todaymn}
if [ $[filedate -lt today ]
mv $file.mp4 $filedate
mv $file.jpg $filedate
fi
########################################
Cheers
WD
Utter Disaster
Soooooo many errors, trying to run it in shell window:-
pi@raspberrypi:/var/spool/cron/crontabs $ find /CCTV/RearOfHouse/ -type file year=$(file:3:4) month=$(file:7:2) filedate=$(year)&(month) mkdir -p $(filedate)
-bash: syntax error near unexpected token `mkdir'
pi@raspberrypi:/var/spool/cron/crontabs $ find /CCTV/RearOfHouse/ -type file year=$(file:3:4) month=$(file:7:2) filedate=$(year)&(month)
[1] 28625
-bash: file:3:4: command not found
-bash: month: command not found
-bash: file:7:2: command not found
pi@raspberrypi:/var/spool/cron/crontabs $ (mkdir -p $(filedate))-bash: year: command not found
find: Must separate multiple arguments to -type using: ','
House/ -type file year=$(file:3:4) month=$(file:7:2) filedate=$(year)&(month)
-bash: syntax error near unexpected token `find'
[1]+ Exit 1 find /CCTV/RearOfHouse/ -type file year=$(file:3:4) month=$(file:7:2) filedate=$(year)
pi@raspberrypi:/var/spool/cron/crontabs $ find /CCTV/RearOfHouse/ -type, file year=$(file:3:4) month=$(file:7:2) filedate=$(year)&(month) mkdir -p $(filedate)
-bash: syntax error near unexpected token `mkdir'
pi@raspberrypi:/var/spool/cron/crontabs $ find /CCTV/RearOfHouse/ -type, file, year=$(file:3:4), month=$(file:7:2), filedate=$(year)&(month), mkdir -p $(filedate)
-bash: syntax error near unexpected token `,'
pi@raspberrypi:/var/spool/cron/crontabs $ find /CCTV/RearOfHouse/ -type, file, year=$(file:3:4), month=$(file:7:2), filedate=$(year)&(month) mkdir -p $(filedate) -bash: syntax error near unexpected token `mkdir'
pi@raspberrypi:/var/spool/cron/crontabs $ find /CCTV/RearOfHouse/ -type, file, year=$(file:3:4), month=$(file:7:2), filedate=$(year)&(month) echo filedate
-bash: syntax error near unexpected token `echo'
pi@raspberrypi:/var/spool/cron/crontabs $ find /CCTV/RearOfHouse/ -type, file, year=$(file:3:4), month=$(file:7:2), filedate=$(year)&(month)
[1] 30273
-bash: month: command not found
-bash: file:3:4: command not found
-bash: file:7:2: command not found
pi@raspberrypi:/var/spool/cron/crontabs $ -bash: year: command not found
WD