LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-29-2012, 08:44 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
scp then remove


I have some files that want to be copy to remote server , after copy to remote server , then remove the file in sender side , I tried the below command , but not work , can advise what can I do ?

the file can copy to remote side but do not remove it in sending side .

rsync -P ssh -r --delete-after test.txt user@remote:/tmp

Thanks
 
Old 11-29-2012, 08:50 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Why not just
Code:
scp test.txt user@remote:/tmp/ && rm -f test.txt
 
Old 11-29-2012, 09:21 PM   #3
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by suicidaleggroll View Post
Why not just
Code:
scp test.txt user@remote:/tmp/ && rm -f test.txt
thanks reply ,

can advise if I would like to verify before remove , if the files is successfuly copy to remote server , then remove it , what can I do ?

thanks.
 
Old 11-29-2012, 09:28 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by ust View Post
thanks reply ,

can advise if I would like to verify before remove , if the files is successfuly copy to remote server , then remove it , what can I do ?

thanks.
The && between the two commands performs an exit status check. It only runs the second command if the first command exits with a successful code. If there is an error in the scp, the exit code will reflect that, and the && will prevent the rm from running. If you'd like further verification, you could scp the file, then perform a diff (assuming the file isn't unreasonably large) to compare against the local file before removing it. Something like
Code:
scp test.txt user@remote:/tmp/
ssh user@remote cat /tmp/test.txt | diff - test.txt
if [[ $? -eq 0 ]]; then
   rm -f test.txt
else
   echo "ERROR: File did not transfer properly"
fi

Last edited by suicidaleggroll; 11-29-2012 at 09:29 PM.
 
Old 11-30-2012, 12:04 AM   #5
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by suicidaleggroll View Post
The && between the two commands performs an exit status check. It only runs the second command if the first command exits with a successful code. If there is an error in the scp, the exit code will reflect that, and the && will prevent the rm from running. If you'd like further verification, you could scp the file, then perform a diff (assuming the file isn't unreasonably large) to compare against the local file before removing it. Something like
Code:
scp test.txt user@remote:/tmp/
ssh user@remote cat /tmp/test.txt | diff - test.txt
if [[ $? -eq 0 ]]; then
   rm -f test.txt
else
   echo "ERROR: File did not transfer properly"
fi

thanks reply ,
If I would like to copy many file , not just one single file "test.txt" , how to verify it ?

Thanks.
 
Old 11-30-2012, 06:15 AM   #6
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
rsync -azSP --delete-after /path-to/dir receiving-hostname:/receivingpath/dir

This should work., the files which are copied are deleted by the receiver.
 
Old 11-30-2012, 06:16 AM   #7
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Try to add user keys in either ways & make sure of the permissions of the files.
 
Old 11-30-2012, 07:44 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
Quote:
Originally Posted by RaviTezu View Post
rsync -azSP --delete-after /path-to/dir receiving-hostname:/receivingpath/dir

This should work., the files which are copied are deleted by the receiver.
I do not think rsync can delete source files:
-a means archive, -z means compression, -S sparse files and -P means --partial --progress. --partial means to avoid removing partially transferred files and --progress will display a progress bar. --delete after will delete files on the receiver side. There is no option to delete anything on the sender side.
 
Old 11-30-2012, 08:12 AM   #9
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
Hey pan64,

--remove-sent will delete the files at the source.

& What you said in the above comment is correct.
 
Old 11-30-2012, 08:36 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
yes, that is --remove-source-files. and there are some restrictions about its usage (see man page)
 
Old 11-30-2012, 12:23 PM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,916

Rep: Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689
Quote:
Originally Posted by ust View Post
thanks reply ,
If I would like to copy many file , not just one single file "test.txt" , how to verify it ?

Thanks.
ust, you've been posting here for NINE YEARS...yet always ask people to write scripts for you, and you don't seem to want to do much for yourself. Can you not read the man pages of these commands???

Sorry if this sounds nasty, but really...given your posting history, you don't show much effort on your part. In this case, someone spoon-fed you a script (again)...so why can't you make a small change to it on your own? Why can't you just RUN that script on your own to verify the results? If after nine years of being an administrator, you can't read a man page or think to yourself "Hmm...this script is copying one file now. Perhaps if I just change it to be a wildcard/pattern, it would work that way. Why don't I try it?", then why do you continue in that role?
 
  


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
Centos 6.3 host+guest: try scp to guest: scp cmd not found. ssh ok chrism01 Linux - Virtualization and Cloud 3 08-24-2012 02:52 AM
[SOLVED] ssh scp key not working to ssh/scp without password rjo98 Linux - Newbie 9 08-22-2011 05:28 PM
scp does not work and gives the following error message: scp: FATAL: Executing ssh1 i akay Linux - Networking 16 09-29-2008 12:41 AM
# yum remove dbus - trying to remove the whole system... atnonis Fedora 4 11-23-2007 07:31 AM
apt-get remove chrony doesn't remove all? asgerhallas Debian 3 06-05-2007 06:37 AM


All times are GMT -5. The time now is 03:09 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration