LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 05-25-2011, 03:40 AM   #1
Monika32011
LQ Newbie
 
Registered: Apr 2011
Posts: 7

Rep: Reputation: 0
Unhappy How to transfer files between two server after finding.


Hello experts,

I want to search for 1 file (say test.txt) on first server and all the output of this search to be greped as per my requirement and then transfered on the second server at the same location where they were on first server.

for eg,
output of search of file (test.txt) >> output.txt
/tmp/test.txt
/home/cpan/test.txt
/opt/cpanel/test.txt

Now I want to grep this output to only related to cpanel,

for f in `cat output.txt`
echo $f | grep "cpanel"

if [ $? -eq 0 ]
then do scp.
But I am bit confused here, as in how to use scp command here.
scp $f root@second_server:/$f ?
Is this right? This doesnt seem to working.
Please advise.

Regards
Monika
 
Old 05-25-2011, 07:04 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,523

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
See if something like this will work for your needs:
Code:
#!/bin/bash

cat output.txt | grep cpanel | while read file
do
        dir=`dirname "$file"`
        scp "$file" root@second_server:"$dir"
done
Note: I placed $file and $dir in double-quotes in case either has a white-space in their respective file name.
 
Old 05-25-2011, 07:26 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,653
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
Quote:
Originally Posted by dwhitney67 View Post
Code:
cat output.txt | grep cpanel | while read file
No need for cat here, this will do the job:
Code:
grep cpanel output.txt| while read file
 
Old 05-26-2011, 03:47 AM   #4
Monika32011
LQ Newbie
 
Registered: Apr 2011
Posts: 7

Original Poster
Rep: Reputation: 0
thanks this worked

Code:
do
        dir=`dirname "$file"`
        scp "$file" root@second_server:"$dir"
done
 
  


Reply

Tags
scp, transfer


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
[SOLVED] using kermit to transfer files with a 3-server system doublec16 Linux - Networking 6 04-12-2011 08:02 AM
Can i transfer files from linux server to windows via RSH barde General 3 03-13-2009 06:04 AM
fastest way to transfer 50gb of files from old server to new? CrewXp Linux - Software 6 08-16-2007 06:56 AM
Transfer 1000000 files (130GB) server to server via shell masali Linux - Software 2 04-04-2007 02:08 PM
How do I dial in to a remote server and transfer files? yilez Linux - Networking 1 05-18-2004 11:40 AM


All times are GMT -5. The time now is 11:53 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration