Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-25-2011, 03:40 AM   #1
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

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.

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

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
See if something like this will work for your needs:

cat output.txt | grep cpanel | while read file
        dir=`dirname "$file"`
        scp "$file" root@second_server:"$dir"
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
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

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

Original Poster
Rep: Reputation: 0
thanks this worked

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


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration