Capture scp output

I have a simple script that uses scp to copy some files from one server to another. I want to capture the files that are copied but simple redirection to a file does not work.

So I want to capture this output from the scp command in a log file.

-bash-3.00$ scp -pr /export/jumpstart/Files server2:/export/jumpstart
config.driver        100% |*********************************************************|  1026       00:00
hardening.driver     100% |*********************************************************|  3876       00:00
secure.driver        100% |*********************************************************|   493       00:00
user.init            100% |*********************************************************|  2588       00:00
whole_zone.cfg       100% |*********************************************************|   122       00:00
sparse_zone.cfg      100% |*********************************************************|   276       00:00
sudoers.20071022     100% |*********************************************************|  6142       00:00
sudoers.20071023     100% |*********************************************************|  6142       00:00
sudoers.20071024     100% |*********************************************************|  6649       00:00
sudoers.20071024v1   100% |*********************************************************|  6933       00:00
sudoers.20071026     100% |*********************************************************|  7053       00:00
sudoers              100% |*********************************************************|  7383       00:00
ntp.conf-prd         100% |*********************************************************|   142       00:00
ntp.conf-dr          100% |*********************************************************|   136       00:00

-bash-3.00$

That's a progress meter and would look awful if captured to a file as it contains cursor control codes.

Is there a way I could just capture the files that have been copied and their sizes, without the progress meter ?

This is not too good because stdin has to be a terminal:-

#!/bin/sh

ssh </dev/tty >output -i .ssh/somekey -t user@localhost scp -i .ssh/somekey files.... user@localhost:directory/

But works by forcing the allocation of a pseudo-terminal so scp thinks it's stdout is writing to a terminal.

Another option would possibly to use 'script'.

1 Like

I can't use script, as the scp is just a line in a script I am using to copy files. I just wanted to have the files that get copied listed in a log file.

Perhaps a copy/paste into a text file then. :wink:

You are joking right..