alternate output for progressmeter

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I used scp in some background process for transferring large files
which took some hours.
For this I needed a less fancy output, preferable parseble by a script
, so I could regularly see how far the transfer was

The adaptions I made to progressmeter.c and .h are underneath my mail as a patch

Some sample output how it looks now:
:~/src/openssh-5.3p1$ ./scp -l 60000 test.bin hans@localhost:.
progress test.bin :   0%    0     0.0KB/s   --:-- ETA
progress test.bin :   7% 7488KB   7.3MB/s   00:12 ETA
progress test.bin :  15%   14MB   7.3MB/s   00:11 ETA
..
progress test.bin :  98%   94MB   7.3MB/s   00:00 ETA
progress test.bin : 100%   95MB   7.3MB/s   00:13 done

With a simple script you can now easily control the output and save
the progress somewhere:

#!/bin/bash
# --- only update status every 10 seconds
statfn=scp1.status
refresh=10
no=0
./scp -l 60000 test.bin hans@localhost:. 2>&1|while read id fn sep
perc size speed estim eta
do
  ((state=no % refresh))
  [[ "$eta" = "done" || $state -eq 0 ]] && echo "`date +"%Y-%m-%d
%H:%M:%S"` $fn $perc $size $speed $estim $eta" >$statfn
  ((no=no+1))
done

The patch only adds this functionality as an option, default the
original layout is used.
Only when variable progresstype is set to nonzero this alternate
output is selected.
For selecting the alternate output it would only require some
commandline option in scp.c and do the isatty check only when
progresstype==0

Let me know your comments...

Hans

--- progressmeter.h	2006-03-26 05:30:02.000000000 +0200
+++ progressmeter_new.h	2009-10-24 20:35:35.168288539 +0200
@@ -23,5 +23,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

+extern	int	progresstype;
+
 void	start_progress_meter(char *, off_t, off_t *);
 void	stop_progress_meter(void);


--- progressmeter.c	2006-08-05 04:39:40.000000000 +0200
+++ progressmeter_new.c	2009-10-24 20:32:45.455788330 +0200
@@ -74,12 +74,15 @@
 static int win_size;		/* terminal window size */
 static volatile sig_atomic_t win_resized; /* for window resizing */

+int	progresstype = 0;	/* use default tty progress reporting */
+
 /* units for format_size */
 static const char unit[] = " KMGT";

 static int
 can_output(void)
 {
+	if (progresstype) return 1;
 	return (getpgrp() == tcgetpgrp(STDOUT_FILENO));
 }

@@ -158,9 +161,9 @@

 	/* filename */
 	buf[0] = '\0';
-	file_len = win_size - 35;
+	file_len = (progresstype)?(strlen(file)+11):(win_size - 35);
 	if (file_len > 0) {
-		len = snprintf(buf, file_len + 1, "\r%s", file);
+		len = snprintf(buf, file_len + 1, (progresstype)?"progress %s
:":"\r%s", file);
 		if (len < 0)
 			len = 0;
 		if (len >= file_len + 1)
@@ -195,7 +198,7 @@
 		stalled = 0;

 	if (stalled >= STALL_TIME)
-		strlcat(buf, "- stalled -", win_size);
+		strlcat(buf, (progresstype)?"-stalled-":"- stalled -", win_size);
 	else if (bytes_per_second == 0 && bytes_left)
 		strlcat(buf, "  --:-- ETA", win_size);
 	else {
@@ -219,10 +222,14 @@
 		if (bytes_left > 0)
 			strlcat(buf, " ETA", win_size);
 		else
-			strlcat(buf, "    ", win_size);
+			strlcat(buf, (progresstype)?" done":"    ", win_size);
 	}

-	atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1);
+	if (progresstype) {
+		strlcat(buf,"\n",win_size);
+		atomicio(vwrite, STDOUT_FILENO, buf, strlen(buf));
+	} else
+		atomicio(vwrite, STDOUT_FILENO, buf, win_size - 1);
 	last_update = now;
 }

@@ -234,7 +241,7 @@

 	save_errno = errno;

-	if (win_resized) {
+	if (progresstype==0 && win_resized) {
 		setscreensize();
 		win_resized = 0;
 	}
@@ -257,12 +264,16 @@
 	stalled = 0;
 	bytes_per_second = 0;

-	setscreensize();
+	if (progresstype)
+		win_size=MAX_WINSIZE;
+	else {
+		setscreensize();
+		signal(SIGWINCH, sig_winch);
+	}
 	if (can_output())
 		refresh_progress_meter();

 	signal(SIGALRM, update_progress_meter);
-	signal(SIGWINCH, sig_winch);
 	alarm(UPDATE_INTERVAL);
 }

@@ -278,7 +289,8 @@
 	if (cur_pos != end_pos)
 		refresh_progress_meter();

-	atomicio(vwrite, STDOUT_FILENO, "\n", 1);
+	if (progresstype==0)
+		atomicio(vwrite, STDOUT_FILENO, "\n", 1);
 }

 /*ARGSUSED*/

[Index of Archives]     [Open SSH Unix Development]     [Fedora Users]     [Fedora Desktop]     [Yosemite Backpacking]     [KDE Users]     [Gnome Users]

  Powered by Linux