LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   can't capture scp progress bar in output redirect (https://www.linuxquestions.org/questions/programming-9/cant-capture-scp-progress-bar-in-output-redirect-841601/)

hedpe 10-31-2010 09:59 PM

can't capture scp progress bar in output redirect
 
Hi all,

I would really like to capture the output of scp and my file's progress. Scp updates the transfer rate every 1 second, and I will like to save the transfer rate at every update. So for example, if the file transfer takes 30 seconds, I would like 30 reports of the transfer rate.

The output looks like:
Code:

file.dat                                  1% 3664KB 938.5KB/s  05:48
Whenever I try a simple redirect like:
Code:

scp file.dat 192.168.1.100:~/ &> output
... it does not save the rate at every update, it only shows the final rate.

If I try using typescript by starting "script" ... it's the same deal.

I'd greatly appreciate any suggestions, thanks!

ciotog 10-31-2010 10:33 PM

scp uses the "isatty()" function call to see if its output goes someplace sane, and doesn't print anything if it's not a tty (frankly I'm surprised you get the final update).

Anyway, try this:
Code:

ssh localhost -t scp file.dat 192.168.1.100: > output
This requires public key authentication to be working on localhost.

hedpe 10-31-2010 10:37 PM

Quote:

Originally Posted by ciotog (Post 4145435)
scp uses the "isatty()" function call to see if its output goes someplace sane, and doesn't print anything if it's not a tty (frankly I'm surprised you get the final update).

Anyway, try this:
Code:

ssh localhost -t scp file.dat 192.168.1.100: > output
This requires public key authentication to be working on localhost.

thanks a bunch for the suggestion! I have public key authentication working on the localhost. I am simply do "ssh localhost" and without entering a password, I will connected.

However, whenever I try this command I keep getting:
Code:

connection to localhost closed.
without the file transfering

hedpe 10-31-2010 10:47 PM

eek, got that working... problem was that the file didn't exist in the home directory. but it still doesn't capture each update :\ same as before

ciotog 10-31-2010 11:06 PM

How are you viewing the file "output"? If you're using "cat" then it will output every character as they appear in the file, and scp uses the "carriage return" character to overwrite the last update with the new update, so you'll only see the last output. The file probably does include every update line.

Try using a pager like less, or something like this:
Code:

sed 's/\r/\n/g' output

hedpe 10-31-2010 11:11 PM

hmmmm we are getting somewhere! the file size is continually growing, replace \r doesn't seem to get me very far though. still only shows the final (or current rate)

ciotog 10-31-2010 11:24 PM

Well I guess your version of scp doesn't suppress output when redirecting, so the following ought to work:

Code:

scp file.dat 192.168.1.100: | tr '\r' '\n' > output
Seems to work fairly well for me, although I still have to use "ssh localhost -t" in front.

hedpe 10-31-2010 11:26 PM

Quote:

Originally Posted by ciotog (Post 4145454)
Well I guess your version of scp doesn't suppress output when redirecting, so the following ought to work:

Code:

scp file.dat 192.168.1.100: | tr '\r' '\n' > output
Seems to work fairly well for me, although I still have to use "ssh localhost -t" in front.

woohoo that worked! thanks a bunch for all of your help, I really appreciate it :)


All times are GMT -5. The time now is 01:13 PM.