My IP camera can only upload images to the same directory (/mnt/NAS/IPC_FTP/) using FTP. I would like to organize these snapshots by date, so I wrote the following script to automatically move all images from yesterday to a new directory (for example to /mnt/NAS/IPC_FTP/2015-07-14/):
A date field is a part of the filename, so it was easy the find all images uploaded on yesterday.
A cron job is added to services-start to schedule the script:
However, it only works if I run the script manually from the console...
I can see in the router's log that the cron job runs the script at the specified time, but it has no effect. What can be the problem? Has the cron job had the necessary permissions to move files?
Thank you very for the help in advance!
Code:
#!/bin/sh
DIR="/mnt/NAS/IPC_FTP/"$(date -d @$(( $(date +"%s") - 86400)) +"%Y-%m-%d")"/"
NAME=".*"$(date -d @$(( $(date +"%s") - 86400)) +"%Y%m%d")".*"
mkdir $DIR
find /mnt/NAS/IPC_FTP/ -type f -regex $NAME -exec mv {} $DIR \;
A date field is a part of the filename, so it was easy the find all images uploaded on yesterday.
A cron job is added to services-start to schedule the script:
Code:
#!/bin/sh
cru a ipc_ftp "1 4 * * * /jffs/scripts/ipc_ftp.sh"
sleep 10
/opt/etc/init.d/rc.unslung start
However, it only works if I run the script manually from the console...
I can see in the router's log that the cron job runs the script at the specified time, but it has no effect. What can be the problem? Has the cron job had the necessary permissions to move files?
Thank you very for the help in advance!