Help - Script to move files?

Status
Not open for further replies.

depasseg

FreeNAS Replicant
Joined
Sep 16, 2014
Messages
2,874
I have a webcam that uploads pictures every minute to a server. I would like to organize the pictures into folders. I've tried writing even a basic script and I suck. Is there anyone out there that can help me out?

I have thousands of pictures in /var/www/cam/archive/current/

Filenames are cam-yyyy-mm-dd-hhmm.jpg

I would like to create a cron job that I can run daily or weekly which would move whatever files are in that folder to /var/cam/archive/yyyy/mm/(same filename).jpg.

Anyone up for a challenge?

Thanks,
Greg
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Well, I'll not do the script for you but I can explain the steps to do it:

List the files with ls and put the result in a variable.
Do a for() on this variable.
Extract the yyyy and mm with awk (awk -F"-" '{print $2}' for yyyy, use $3 for the mm) and put them in variables.
Do a if() to see if the directory yyyy exists, if not create it.
Do the same for the mm directory.
Move the file with mv.​
 
Status
Not open for further replies.
Top