Unfortunately no one can be told what fun_plug is - you have to see it for yourself.
You are not logged in.
I'm trying to run the following script. I have a camera that, on its own, saves .asf files to a directory on the NAS (/mnt/HD_a2/ipcamera). Well, every night at 11:55 I want to take the daily files and create a folder and move them into the folder.
My script creates the folder, but for some reason is not moving the files. What am I doing wrong?
#!/ffp/bin/sh
###########
# Settings
###########
cd /mnt/HD_a2/ipcamera
dateCmd="/bin/date"
mkdirCmd="/bin/mkdir"
chmodCmd="/bin/chmod"
echoCmd="/bin/echo"
wcCmd="/ffp/bin/wc"
dstLog="/mnt/HD_a2/ipcamera/ipcam_cleanup.log"
theDirDate=$(${dateCmd} "+%Y-%m-%d")
dstDir=${theDirDate}
theRecDate=$(`${dateCmd} "+rec_%Y%m%d"`)
logDate=$(${dateCmd} "+%Y_%m_%d-%H:%M:%S")
if [ ! -d "${dstDir}" ];
then
numOfRec=$(find . -name "${theRecDate}*" | ${wcCmd} -l)
if test ${numOfRec} -gt 0;
then
${echoCmd} "++" >> ${dstLog}
${echoCmd} "=================="${theDirDate}"===================" >> ${dstLog}
${echoCmd} [${logDate}] Making new directory \"${dstDir}\">> ${dstLog}
${mkdirCmd} ${dstDir}
${echoCmd} [${logDate}] Changing directory persmissions >> ${dstLog}
${chmodCmd} 777 ${dstDir}
${echoCmd} [${logDate}] Finding recordings that match today\'s date >> ${dstLog}
${echoCmd} [${logDate}] ${numOfRec} recording\(s\) found >> ${dstLog}
${echoCmd} [${logDate}] Moving recording\(s\) into directory \"${dstDir}\" >> ${dstLog}
find . -name "${theRecDate}*" -exec mv {} /mnt/HD_a2/ipcamera/${dstDir} \;
${chmodCmd} 777 -R ${dstDir}
${echoCmd} "==================[end of log]======================" >> ${dstLog}
else
${echoCmd} "++" >> ${dstLog}
${echoCmd} "=================="${theDirDate}"===================" >> ${dstLog}
${echoCmd} [${logDate}] No recordings found, nothing to move. >> ${dstLog}
${echoCmd} "==================[end of log]======================" >> ${dstLog}
fi
else
${echoCmd} [${logDate}] \"${dstDir}\" already exists, nothing will be done. >> ${dstLog}
${echoCmd} "==================[end of log]======================" >> ${dstLog}
fi
exit 0
The recording files are prefixed by the date and time. An example is: "rec_20120316163357.asf". I added the ` and ` in the $theRecDate variable and it is moving EVERY file and folder inside /mnt/HD_a2/ipcamera to a NEW folder called 2012-03-16. But I only want the files that match the date of the day (not folders and not other days files).
Thanks for anyone who is able to help
Last edited by bound4h (2012-03-17 06:12:23)
Offline
First of all, I think that:
$(`${dateCmd} "+rec_%Y%m%d"`)
should be:
$(${dateCmd} "+rec_%Y%m%d")
$(...) is the same as `...`, so it's either one or the other.
The script you wrote forces you to run it just before the day ends, which is a bit limiting. Why not use sed to parse the file name and convert it to the date. Try running this code example, that for each file will generate it's "correct" destination directory (it doesn't make any changes to your system):
for file in $( ls rec_*.asf ) ; do echo $file | sed 's@rec_\([0-9]\{4\}\)\([0-9]\{2\}\)\([0-9]\{2\}\).*@\1-\2-\3@'; done
sed expressions tend to be a bit cryptic, because of all the escaping ('\') but it's a very useful tool. This should get you up to speed in not time: http://www.grymoire.com/Unix/Sed.html
good luck!
Last edited by scaramanga (2012-03-17 11:36:57)
Offline
Assuming everything else is ok, could it be as simple as:
find . -name "${theRecDate}*" -exec /ffp/bin/mv {} /mnt/HD_a2/ipcamera/${dstDir} \;
Offline
Thanks Scara, I am considering re-writing it using your suggestion.
And thanks FunFiler, that did it! Oddly enough
Offline
Nothing odd about it really since you said everything else worked and this was the only statement missing the full path.
Offline