LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-25-2007, 10:40 PM   #1
ryanlum
Member
 
Registered: Jul 2007
Posts: 47

Rep: Reputation: 15
Need help with RSYNC


hey guyz,

I am currently using rsync.. i have a problem though.. if i were to copy the files from the folder, and currently rsync is using the file, the mv will fail.

Is there anyway to go around this to let the script know that the file is currently being used by rsync?
 
Old 07-26-2007, 01:48 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,352

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If rsync is reading the file and you want to cp the file, that will work.
If rsync is reading the file and you want to mv the file, check cmds lsof, fuser.
Ditto the latter if rsync is writing to the file.
 
Old 07-26-2007, 02:01 AM   #3
gloriant
Member
 
Registered: Sep 2004
Distribution: Debian{Woody,Sarge,Etch}, UbuntuLTS6.06, SuSE{6.2,8.0}
Posts: 42

Rep: Reputation: 16
you're mingling two concepts here, copy files and the command mv which will move and/or rename files (from one location to another).
Making a copy of the file in use should not be a problem.
 
Old 07-26-2007, 03:11 AM   #4
ryanlum
Member
 
Registered: Jul 2007
Posts: 47

Original Poster
Rep: Reputation: 15
i just want to use mv.

you suggested to use cmds lsof, fuser

how do you use it and which one is better?
becuase i will need to mv the file
 
Old 07-27-2007, 08:27 AM   #5
ryanlum
Member
 
Registered: Jul 2007
Posts: 47

Original Poster
Rep: Reputation: 15
i tried rsync on the command losf...
but it can't seem to detect the file when its being transfered by rsync.
but it doesn't have any probelms for ftp.
any ideaS?
 
Old 11-27-2009, 07:27 AM   #6
gloriant
Member
 
Registered: Sep 2004
Distribution: Debian{Woody,Sarge,Etch}, UbuntuLTS6.06, SuSE{6.2,8.0}
Posts: 42

Rep: Reputation: 16
Quote:
Originally Posted by ryanlum View Post
i tried rsync on the command losf...
but it can't seem to detect the file when its being transfered by rsync.
but it doesn't have any probelms for ftp.
any ideaS?
You could do it like this:

Code:
# file is the file to move.  This should best be absolute path (and even realpath)
file=/home/me/test/file13.txt

# destination is where you want to move the file to. this example suggests it to be
# a directory.
destination=/tmp

# PROC is the name of the process you suspect to be interfering.  This name should be 
#   a name that would appear as first field in an lsof output.
PROC=rsync

# PROCUSER is the user the suspected PROC could be running as.  Leave empty if unknown.
# e.g.: PROCUSER=${USER};
PROCUSER="";

[ -z "${file}" ] && echo "ERROR: file is not set." >&2 && exit;
[ ! -f "${file}" ] && echo "WARNING: ${file} is no file";

[ -z "${destination}" ] && echo "ERROR: destination is not set." >&2 && exit;
[ ! -d ${destination} ] && echo "WARNING: ${destination} is no directory";

# we're looking in the lines of lsof, for a match on
#  running process,... by running user,... keeping file open.
SEARCH='^'${PROC}[ \t].*[ \t]'${PROCUSER}'.*[ \t]'${file}'$';

if ! lsof | grep -q -E "${SEARCH}"; then
  mv ${file} ${destination};
fi

Last edited by gloriant; 11-27-2009 at 07:28 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rsync jwymore Fedora 2 02-08-2007 07:04 AM
Rsync server vs rsync over ssh humbletech99 Linux - Networking 1 10-18-2006 12:10 PM
Rsync anickless Linux - Networking 2 11-21-2005 12:32 PM
Windows Rsync Upload to Linux Rsync - permissions inspleak Linux - Software 0 10-12-2004 02:49 PM
rsync becks.lin Linux - Software 6 03-22-2004 07:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration