LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-13-2009, 06:36 PM   #1
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Rep: Reputation: 36
replacing rm command with a rsync script :-)


Hello all,

I wanted to write a small script,which i would like to use in the place of rm command to move(rather delete) the files to a remote trash directory using rsync.

Does any one know how to delete directories from the source after the files are rsynced to the remote destination? the --remove-source-files works only for files,and leave many empty directories behind.

Secondly,is there a better way to do the samething instead of using a foreach statment?? I guess using rsync in a foreach stmtn,will spawn a new rsync connection everytime.

Code:
#!/usr/bin/perl
use strict;
use warnings;
my $user = "ryan";
my $host = "wsx04";
my $pwd ="";
my $Dir="Wsx02";
foreach (@ARGV) {
`rsync --bwlimit=2048 --remove-source-files --delete -e "ssh -c blowfish" -avzpr $_  $user\@$host:/Backup/Trash/$Dir/`;
}
Thanks All.I'm new to perl
 
Old 11-13-2009, 09:28 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You might create a list of files/directories first, then tar over ssh, then rm (all in a script.)
Kevin Barry
 
Old 11-14-2009, 08:46 AM   #3
kdelover
Member
 
Registered: Aug 2009
Posts: 311

Original Poster
Rep: Reputation: 36
id like to do that ,but i want use it just like how i use rm command :-)
 
Old 11-14-2009, 11:49 AM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You can make a script that does what you want, inferring the correct behavior from the rm options provided, then alias rm to it in your shell. You won't be able to achieve an exact solution without rewriting rm, e.g. if interactive mode is chosen, you'll probably have to back up the files anyway even though rm might leave them there, or if the user doesn't have permission to remove the files, etc. libc has a function called access to see if a user can rwx a file, but I don't know if perl implements something like that.

You can search for the most important options, such as -r, -x, and -- (plus their full-name counterparts) to infer the correct operation and files, then generate an archive, then pass the whole set of args to rm.
Kevin Barry

PS Remember that even though a user might be able to delete a file, they might not be able to recreate it with the same ownership unless they're root.

Last edited by ta0kira; 11-14-2009 at 11:50 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
replacing folder with mv command bashyow Linux - Newbie 8 09-06-2012 05:26 AM
Help with rsync command (or script) multiple file backups luis14 Linux - Software 3 11-08-2007 11:07 PM
replacing a file in a zip from command line davee Linux - General 3 02-28-2006 02:06 PM
a command/script for replacing a word with another jaakkop Programming 14 12-04-2005 11:21 AM
Replacing a particular position in a file thru shell script in Linux sgracelin Programming 7 06-22-2005 08:04 AM


All times are GMT -5. The time now is 02:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration