LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 05-03-2013, 06:51 AM   #1
VicMP3
LQ Newbie
 
Registered: Sep 2012
Location: England/Romania... depends
Distribution: Ubuntu
Posts: 7

Rep: Reputation: Disabled
Question Ubuntu/Cent OS Find and SCP command


Hello,

I'm trying to create a little script to backup some files from a remote linux server to another linux server using a intermediary vpn server.

x=`ssh msc@msc find /path/to/files -mtime +1 -name "filename*"`
scp msc@msc:$x /home/mx

Originally I though this would behave as gzip or other commands and wouldn't mind the newline in the find output.

But it seems it just starts to scp the 1st file and the rest it just outputs errors.

I was wondering if it's possible to change the way linux outputs when using find command . to be more precise can I remove the new line and turn it into space?

Thanks!
 
Old 05-03-2013, 08:41 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
First thing is that you're using a wrong find command. Find should end with either -print or -exec option, like this:
Code:
~$ find /path/to/files -mtime +1 -name "filename*" -print
Second, the way you're saving find command output in x is wrong. You should do something like this:
Code:
#!/bin/bash
ssh msc@msc     ## You can use a password less login here using rsa keys
find /path/to/files -mtime +1 -name "filename*" -print > /tmp/list.txt
while read -r file; do
mv $file /home/mx/
done < /tmp/list.txt
 
1 members found this post helpful.
Old 05-03-2013, 08:51 AM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
this worx for me
Code:
[schneidz@hyper test]$ find . -type f 
./world
./hello
./l33t
[schneidz@hyper test]$ scp `find . -type f` schneidz@xbmc:test
world                                                                                              100%    0     0.0KB/s   00:00    
hello                                                                                              100%    0     0.0KB/s   00:00    
l33t                                                                                               100%    0     0.0KB/s   00:00    
[schneidz@hyper test]$ ssh schneidz@xbmc ls -l test
total 0
-rw-rw-r-- 1 schneidz schneidz 0 May  3 09:50 hello
-rw-rw-r-- 1 schneidz schneidz 0 May  3 09:50 l33t
-rw-rw-r-- 1 schneidz schneidz 0 May  3 09:50 world
 
Old 05-03-2013, 08:57 AM   #4
VicMP3
LQ Newbie
 
Registered: Sep 2012
Location: England/Romania... depends
Distribution: Ubuntu
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by shivaa View Post
First thing is that you're using a wrong find command. Find should end with either -print or -exec option, like this:
Code:
~$ find /path/to/files -mtime +1 -name "filename*" -print
Second, the way you're saving find command output in x is wrong. You should do something like this:
Code:
#!/bin/bash
ssh msc@msc     ## You can use a password less login here using rsa keys
find /path/to/files -mtime +1 -name "filename*" -print > /tmp/list.txt
while read -r file; do
mv $file /home/mx/
done < /tmp/list.txt
Thanks for the help guys.

In the mean time i tried this and it worked with my SCP.

find /telos/msc/DATA -mtime +1 -name "CDR*" | xargs echo
 
Old 05-03-2013, 10:05 AM   #5
VicMP3
LQ Newbie
 
Registered: Sep 2012
Location: England/Romania... depends
Distribution: Ubuntu
Posts: 7

Original Poster
Rep: Reputation: Disabled
Lightbulb

ah in the end i did it with a while

my final script.


Code:
ssh msc@msc find /path/to/files -mtime +1 -name "CDR*" | while read fName; do scp msc@msc:${fName} /path/out/; done
x=`find /path/out/ -name "CDR*"`
gzip -f $x
Works fine this way. just though I'd share it if anyone needs anything similar.
 
  


Reply



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
Ubuntu server guest on Cent OS 6.0 host. ThomasRonshof Linux - Virtualization and Cloud 5 10-26-2011 07:13 AM
ubuntu and cent-OS on vmware player avee137 Linux - Newbie 1 04-27-2010 03:45 AM
Expect script, scp and find command unihiekka Programming 1 10-17-2008 03:11 PM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 06:02 AM
pipe find output to scp groundhog_killer Linux - Networking 2 02-14-2006 10:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:10 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
Open Source Consulting | Domain Registration