LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-18-2008, 04:45 PM   #1
gokuls
LQ Newbie
 
Registered: Dec 2005
Posts: 5

Rep: Reputation: 0
How to redirect the SCP command output to text file.


Hi,

I will first explain my requirement..I'm copying file or dir from other server.

Let say...
i am currently logged in 192.168.1.11 box and copying the dir from 1.10 box.(lets assume this is password less login).

#scp -r 192.168.1.10:/home/test/dir1 /myhome

so the output will be something like this..

dir1 100%|*************************************************| 123KB 12:00:01.. etc...something like this..

I want to redirect the above output to one text file..How to do that..Please guide me...
I tried to redirect using > and | option [result file will be created but empty]

Let me know incase of any questions....

Thanks
Gokul
 
Old 03-18-2008, 04:59 PM   #2
sajro
Member
 
Registered: Jan 2008
Location: Tennessee
Distribution: Arch, Debian, Ubuntu, Puppy
Posts: 39

Rep: Reputation: 15
I don't know exactly, but maybe this would work?
Code:
#cat `scp -r 192.168.1.10:/home/test/dir1 /myhome` > file.txt
 
Old 03-19-2008, 08:32 AM   #3
gokuls
LQ Newbie
 
Registered: Dec 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for your reply...

But it didn't work....
 
Old 03-19-2008, 12:24 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Code:
scp -r 192.168.1.10:/home/test/dir1 /myhome 2>&1|tee logfile


Cheers,
Tink
 
Old 03-21-2008, 01:39 AM   #5
gokuls
LQ Newbie
 
Registered: Dec 2005
Posts: 5

Original Poster
Rep: Reputation: 0
I tried above command and i got only empty file...


Thanks
Gokul
 
Old 03-23-2008, 03:17 AM   #6
gokuls
LQ Newbie
 
Registered: Dec 2005
Posts: 5

Original Poster
Rep: Reputation: 0
any other suggestion plz....
 
Old 03-29-2008, 12:41 PM   #7
gokuls
LQ Newbie
 
Registered: Dec 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
Code:
scp -r 192.168.1.10:/home/test/dir1 /myhome 2>&1|tee logfile


Cheers,
Tink


any suggestion?? i need to find the answer for above question.
need help!
 
Old 03-29-2008, 01:16 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,965
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
OK. scp shows some weird behaviour here, I wasn't aware of that.
The only way I managed to capture any output from it was using
script (which is quite ugly because of the progress meter).

You'd then need to do some post-processing of the typescript
to get the last part of the output - the one with 100% ...


Cheers,
Tink
 
Old 08-31-2009, 04:04 AM   #9
Susannah
LQ Newbie
 
Registered: Aug 2009
Posts: 1

Rep: Reputation: 0
Worked for me:

Code:
scp -v sourcefile.txt user@targetsystem:/home/test/dir1 >&out.txt
the out.txt file contains all kind of debug info and the last line contains the exit status...

Rgds
Su
 
Old 12-02-2009, 09:59 AM   #10
cloudmilk
LQ Newbie
 
Registered: Dec 2009
Location: Paris, France
Distribution: Debian
Posts: 6

Rep: Reputation: 1
Lightbulb

I'd suggest not to forget the bash mechanism with

scp sourcefile.txt user@targetsystem:/home/test/dir1 && echo "scp done" > out.txt

The only thing you don't have is the file size.

The && effect is that what follows (echo here) will only occur if the first part (scp) ended normally (exit 0). Otherwise nothing happends

In that case scp -q (quiet) can be used.
 
Old 02-22-2012, 02:12 AM   #11
peterhupston
LQ Newbie
 
Registered: Apr 2009
Location: SA/Botswana
Distribution: SuSE
Posts: 3

Rep: Reputation: 0
This worked for me

scp -v filetocopy.txt admin@10.20.0.1:/data/ 2> scplog.txt
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to redirect the output of find command to input of egrep babu198649 Linux - Newbie 2 12-27-2007 03:50 AM
command output to text file? meniscus Linux - Newbie 4 10-05-2006 05:29 AM
How to redirect output to a file? mus1402 Linux - Newbie 2 02-05-2006 09:42 AM
How to redirect standard output of piped command to log file andrewstr Linux - General 10 02-04-2004 02:07 PM
output from cpio won't redirect to file rawii Programming 5 01-27-2004 01:49 PM


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