LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to redirect the SCP command output to text file. (https://www.linuxquestions.org/questions/linux-general-1/how-to-redirect-the-scp-command-output-to-text-file-629034/)

gokuls 03-18-2008 05:45 PM

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

sajro 03-18-2008 05:59 PM

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

#cat `scp -r 192.168.1.10:/home/test/dir1 /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

Code:

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


Cheers,
Tink

gokuls 03-21-2008 02:39 AM

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


Thanks
Gokul

gokuls 03-23-2008 04:17 AM

any other suggestion plz....

gokuls 03-29-2008 01:41 PM

Quote:

Originally Posted by Tinkster (Post 3094009)
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!

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


Cheers,
Tink

Susannah 08-31-2009 05:04 AM

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

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@10.20.0.1:/data/ 2> scplog.txt


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