0

I noticed a strange, but extremely useful, feature of scp. So far I haven't seen it in any other application.

Try:

$ scp very_large_file host:directory
very_large_file    0%  1234KB  1.5MB/s  16:30 ETA
^Z
[1]+ Stopped scp...
$ bg
[1]+ scp... &
$

At this state, no more output clutters the shell, so it's nicely workable. The data is transmitted in the background as is easily confirmed. However, when one wants to check again how the progress is going:

$ fg
scp...
very_large_file    0%  7890KB  1.5MB/s  15:30 ETA

Now that scp is back in foreground the live progress updates again.

I miss this gravely in, for example, wget, which will happily throw its output at me when I'm trying to enter some other commands. (Yet I'm interested in seeing its progress at least once in a while.) With multiple wgets running in parallel in the same terminal window the output is just a messy mix and the command line becomes entirely unusable.

I suppose I could write a small wrapper that would pipe any application and add this functionality. How does scp detect if it's running in shell foreground or background?

The Vee
  • 11,420
  • 5
  • 27
  • 60
  • I marked this as a duplicate of a question that explains how `scp` can detect when it's in the background. I'm not sure how you expect that to help you with `wget`, unless your plan is to modify the code. – Barmar Sep 20 '16 at 19:46
  • 1
    ssh uses this check: `if (getpgrp() == tcgetpgrp(STDOUT_FILENO)) { /* do output */ }` – Mark Plotnick Sep 20 '16 at 20:32

0 Answers0