Hi ULF,
Good day! I'm working on a LINUX Suse server and I have an entry in CRON which looks like this below:
0 5 * * * /usr/bin/find /opt/nsfw/var/partition-all/ -name "RCV_SASN*" -exec mv '{}' /opt/nsfw/var/rcv-archive/ \;
This tool runs everyday at 5am and it will just move the files from one sub-dir to another. I still can't figure out, why sometimes we're experiencing some problems in a way that some of the files are not being moved and some are successful. With the same naming convention being (-name RCV-SASN*), still some are left and worse is, some of the files are already dated past few (2-5) days, given that it's running everyday.
I checked the sub-dir "rcv-archive" and observed that some of the latest dated files were successfully moved while some are not.
I thought of some possible reasons like:
- Does the "mv" command has a limit, like even it will run the tool it will only move certain counts of files?
- Is it safe to say that I must put "&" at the end of the line, for it not to be interrupted if someone worked during that time, then let's say for example when the CRON runs in background at 5am (then since the files to be moved have a huge count, therefore it will take quite slow), the user might do some "CTRL+C" action without knowing that the command has been ran. So as if he interacts or cancels the script in working in background. Is it?
Thanks and God bless!
BR,
rymnd_12345
Try redirecting stderr to a file, then monitor that file.
0 5 * * * /usr/bin/find /opt/nsfw/var/partition-all/ -name "RCV_SASN*" -exec mv '{}' /opt/nsfw/var/rcv-archive/ 2>>/path/to/cron.log \;
No need for & on a crontab line - the task is already in background.
There is scope for the script to go wrong if any filename is duplicated on the input side or if any filename already exists on the output side.
There is also scrope for the script to go wrong if any file on the input side is open for writing by an application at the time the cron fires.
I would take the long line out of crontab and place it in an executable script with some proper error checking and error logging. Then execute the script from crontab.
Hi ThomasMcA,
Thanks for your input 
Hi methyl,
Appreciate your suggestion, I have also read some related issues on this and they suggested same to put the long line into a script and put the script in CRON instead.
My only question on this is, what's the difference of putting the long line command into a script and not? Please advise.
BR,
rymnd_12345
---------- Post updated at 07:28 AM ---------- Previous update was at 01:04 AM ----------
Hi methyl,
I have just created a script containing the whole line, I've did something like this:
# cat rcv-move.sh
#!/bin/bash
/usr/bin/find /opt/nsfw/var/partition-all/ -name "RCV_SASN*" -exec mv '{}' /opt/nsfw/var/rcv-archive/ \;
Is this correct? Also, I have already put the executable rcv-move.sh script on the CRON redirecting error logs into a file, please refer below:
0 5 * * * /root/scripts/rcv-move.sh 2>>/tmp/cron.log
Please advise.
I hope I can get also a feedback on my question about their difference 
Thanks!
BR,
Raymond
Hi methyl,
Good morning! I hope I can get some brief explanation on my question above, also please confirm if my script is already good, and so with the new CRON entry that I will input.
Thanks:)
BR,
rymnd_12345
A script allows for more robust code. A script is usually easier to read and edit than a long cron entry. It is also easier to add intelligence to a script, such as "if" loops that check for file existence before trying to process the file. A script can also have error handling, or even send email alerts.
Sorry, in preparing this post I realised a big fault in the original cron.
Stopped for a think.
Is this the prefix name of multiple FILES or a prefix of the name of multiple DIRECTORIES?
Also, is it RVC-SASN or RVC_SASN ? (posts are inconsistent).