Possible Cause of Files Not Being Moved?


 
Thread Tools Search this Thread
Operating Systems Linux Possible Cause of Files Not Being Moved?
# 1  
Old 05-10-2012
Possible Cause of Files Not Being Moved?

Hi ULF,

Good day! I'm working on a LINUX Suse server and I have an entry in CRON which looks like this below:

Code:
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:

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?


Thanks and God bless!

BR,
rymnd_12345
# 2  
Old 05-10-2012
Try redirecting stderr to a file, then monitor that file.

Code:
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 \;

# 3  
Old 05-10-2012
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.
# 4  
Old 05-11-2012
Hi ThomasMcA,

Thanks for your input Smilie


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:
Code:
# 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:
Code:
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 Smilie


Thanks!

BR,
Raymond
# 5  
Old 05-14-2012
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.


ThanksSmilie

BR,
rymnd_12345
# 6  
Old 05-14-2012
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.
# 7  
Old 05-14-2012
Sorry, in preparing this post I realised a big fault in the original cron.

Stopped for a think.

Last edited by methyl; 05-14-2012 at 02:06 PM.. Reason: prepare to rewrite post
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to count the number of files moved?

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)
Discussion started by: Kadikis
4 Replies

2. Shell Programming and Scripting

Column comparison between two files: moved from another post

I have two files as follows: Pval.txt ID Pvalue 91500 0.004 91700 0.007 91800 0.12 91900 0.05 92000 0.99 Freq.txt ID Frequency 90000 56 91500 29 91600 78 91700 60 91800 77 91900 66 92000 70 92100 50 92200 60I need to compare 1st... (19 Replies)
Discussion started by: cs_novice
19 Replies

3. Shell Programming and Scripting

List moved files in text file

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)
Discussion started by: Ashtefere
0 Replies

4. UNIX for Advanced & Expert Users

How to know the user who moved the files to other dir

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)
Discussion started by: srilaxmi
1 Replies

5. Solaris

files updated in last 10 hours should be moved

Hi, I would like to move all files that are updated in last 10 hrs. to some temporary folder. Please help. (3 Replies)
Discussion started by: sanjay1979
3 Replies

6. UNIX for Dummies Questions & Answers

Showing Moved Files

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)
Discussion started by: msb65
5 Replies

7. UNIX for Dummies Questions & Answers

rsync, which files where moved?

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)
Discussion started by: JCR
5 Replies

8. Shell Programming and Scripting

Getting a list of filenames of moved files

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)
Discussion started by: chengwei
3 Replies
Login or Register to Ask a Question