LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-31-2010, 10:59 PM   #1
hedpe
Member
 
Registered: Jan 2005
Location: Pittsburgh
Distribution: Ubuntu
Posts: 378

Rep: Reputation: 30
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!
 
Old 10-31-2010, 11:33 PM   #2
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
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.
 
Old 10-31-2010, 11:37 PM   #3
hedpe
Member
 
Registered: Jan 2005
Location: Pittsburgh
Distribution: Ubuntu
Posts: 378

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ciotog View Post
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
 
Old 10-31-2010, 11:47 PM   #4
hedpe
Member
 
Registered: Jan 2005
Location: Pittsburgh
Distribution: Ubuntu
Posts: 378

Original Poster
Rep: Reputation: 30
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
 
Old 11-01-2010, 12:06 AM   #5
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
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
 
Old 11-01-2010, 12:11 AM   #6
hedpe
Member
 
Registered: Jan 2005
Location: Pittsburgh
Distribution: Ubuntu
Posts: 378

Original Poster
Rep: Reputation: 30
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)
 
Old 11-01-2010, 12:24 AM   #7
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
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.
 
Old 11-01-2010, 12:26 AM   #8
hedpe
Member
 
Registered: Jan 2005
Location: Pittsburgh
Distribution: Ubuntu
Posts: 378

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by ciotog View Post
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
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
mv with progress bar gbowden Linux - General 28 08-14-2013 05:42 AM
How to redirect the SCP command output to text file. gokuls Linux - General 10 02-22-2012 03:12 AM
cp progress bar edwardsiow Linux - General 26 09-04-2011 09:53 AM
cp with progress bar? Rotwang Linux - General 5 04-27-2005 08:49 PM
cp: progress bar chii-chan Linux - General 2 10-30-2003 07:30 PM


All times are GMT -5. The time now is 05:02 PM.

Main Menu
Advertisement
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