Good day! I'm working on a LINUX Suse server and I have an entry in CRON which looks like this below:
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:
1. Does the "mv" command has a limit, like even it will run the tool it will only move certain counts of files?
2. 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?
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.
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:
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:
Please advise.
I hope I can get also a feedback on my question about their difference
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.
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.
I'm writing a script for searching substring in file content and then moving found files. So far I've wrote script shown below
grep -lir 'stringtofind' $1 | xargs mv -t $2
How can i count number of files moved? (4 Replies)
Hi.
I am actually doing all of this on OSX, but using unix apps and script.
I have built my own transparent rsync/open directory/mobility/etc set of scripts for the firm I work at, and it is all almost complete except for ONE THING.
I have the classic problem with rsync where if a user... (0 Replies)
Hi,
I want to know the user ID who moved a file from one directory to another Directory.
Example: File1 created by user A is present in dirA
then some one has moved it to dirB using "mv" command
I want to know the user ID who moved the file to dirB.
As far as i know "ls -lrt" command... (1 Reply)
Hi everyone,
In a directory I have files with various extensions. I would like to move all the files ending in .L2 into a directory: ~/test. But I would also like to show which files are being moved. Of course I could type:
$ ls *.L2
$ mv *.L2 ~/test
Is there a way I can combine these two... (5 Replies)
Hello,
I am using rsync to make sure that my folder "local" mirrors the remote directory "remote". When a file is copied from "remote" to "local", I need to apply a bash script to it. What would be a neat way to do that?
Thanks
ps: is there a way to edit the title of the thread (I am a bit... (5 Replies)
I'm moving a list of files of some extension and I wish to output the moved filenames into a text file, I tried using the command below, but after all the files are moved, I got a blank file.
find /abc/temp -type f -mtime +365 \( -name "*.bak" -o -name "*.log" \) -exec mv -f {} /junk \; >>... (3 Replies)