-   Linux - General (
-   -   How to redirect the SCP command output to text file. (

gokuls 03-18-2008 05:45 PM

How to redirect the SCP command output to text file.

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

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

#scp -r /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....


sajro 03-18-2008 05:59 PM

I don't know exactly, but maybe this would work?

#cat `scp -r /myhome` > file.txt

gokuls 03-19-2008 09:32 AM

Thanks for your reply...

But it didn't work....

Tinkster 03-19-2008 01:24 PM


scp -r /myhome 2>&1|tee logfile


gokuls 03-21-2008 02:39 AM

I tried above command and i got only empty file...


gokuls 03-23-2008 04:17 AM

any other suggestion plz....

gokuls 03-29-2008 01:41 PM


Originally Posted by Tinkster (Post 3094009)

scp -r /myhome 2>&1|tee logfile


any suggestion?? i need to find the answer for above question.
need help!

Tinkster 03-29-2008 02:16 PM

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% ...


Susannah 08-31-2009 05:04 AM

Worked for me:


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...


cloudmilk 12-02-2009 10:59 AM

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.

peterhupston 02-22-2012 03:12 AM

This worked for me
scp -v filetocopy.txt admin@ 2> scplog.txt

All times are GMT -5. The time now is 03:49 PM.