Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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?
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.