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
 
LinkBack Search this Thread
Old 05-25-2011, 02: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, 06:04 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,494

Rep: Reputation: 327Reputation: 327Reputation: 327Reputation: 327
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, 06:26 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Slackware
Posts: 14,860
Blog Entries: 2

Rep: Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796Reputation: 3796
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, 02: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
Trackbacks are Off
Pingbacks are On
Refbacks are 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 07:02 AM
Can i transfer files from linux server to windows via RSH barde General 3 03-13-2009 05:04 AM
fastest way to transfer 50gb of files from old server to new? CrewXp Linux - Software 6 08-16-2007 05:56 AM
Transfer 1000000 files (130GB) server to server via shell masali Linux - Software 2 04-04-2007 01:08 PM
How do I dial in to a remote server and transfer files? yilez Linux - Networking 1 05-18-2004 10:40 AM


All times are GMT -5. The time now is 05:16 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