1

I'm trying to write a bash script using dialog, and part if it involves cloning a few git repositories.

I'd like to use dialog --gauge to show a progress bar as well as showing a --tailbox to show what git is up to.

So far I'm not having any luck getting the progress info from git into a form that dialog will understand.

This is what I've got so far:

git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 | cat > /tmp/gitprocfile &
cat /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50 

I end up with a file in /tmp/gitprocfile that looks like this

Cloning into 'output-dir'...
remote: Counting objects: 103668, done.[K
remote: Compressing objects:   0% (1/23688)   [K
remote: Compressing objects:   1% (237/23688)   [K
remote: Compressing objects:   2% (474/23688)   [K
remote: Compressing objects:   3% (711/23688)   [K
remote: Compressing objects:   4% (948/23688)   [K
remote: Compressing objects:   5% (1185/23688)   [K
remote: Compressing objects:   6% (1422/23688)   [K
remote: Compressing objects:   7% (1659/23688)   [K
remote: Compressing objects:   8% (1896/23688)   [K
remote: Compressing objects:   9% (2132/23688)   [K
remote: Compressing objects:  10% (2369/23688)   [K
remote: Compressing objects:  11% (2606/23688)   [K
remote: Compressing objects:  12% (2843/23688)   [K
remote: Compressing objects:  13% (3080/23688)   [K
remote: Compressing objects:  14% (3317/23688)   [K
remote: Compressing objects:  15% (3554/23688)   [K
remote: Compressing objects:  16% (3791/23688)   [K
remote: Compressing objects:  17% (4027/23688)   [K
remote: Compressing objects:  18% (4264/23688)   [K
remote: Compressing objects:  19% (4501/23688)   [K
remote: Compressing objects:  20% (4738/23688)   [K
remote: Compressing objects:  21% (4975/23688)   [K
remote: Compressing objects:  22% (5212/23688)   [K
remote: Compressing objects:  23% (5449/23688)   [K
remote: Compressing objects:  24% (5686/23688)   [K
remote: Compressing objects:  25% (5922/23688)   [K
remote: Compressing objects:  26% (6159/23688)   [K
remote: Compressing objects:  27% (6396/23688)   [K
remote: Compressing objects:  28% (6633/23688)   [K
remote: Compressing objects:  29% (6870/23688)   [K
remote: Compressing objects:  30% (7107/23688)   [K
remote: Compressing objects:  31% (7344/23688)   [K
remote: Compressing objects:  32% (7581/23688)   [K
remote: Compressing objects:  33% (7818/23688)   [K
remote: Compressing objects:  34% (8054/23688)   [K
remote: Compressing objects:  35% (8291/23688)   [K
remote: Compressing objects:  36% (8528/23688)   [K
remote: Compressing objects:  37% (8765/23688)   [K
remote: Compressing objects:  38% (9002/23688)   [K
remote: Compressing objects:  39% (9239/23688)   [K
remote: Compressing objects:  40% (9476/23688)   [K
remote: Compressing objects:  41% (9713/23688)   [K
remote: Compressing objects:  42% (9949/23688)   [K
remote: Compressing objects:  43% (10186/23688)   [K
remote: Compressing objects:  44% (10423/23688)   [K
remote: Compressing objects:  45% (10660/23688)   [K
remote: Compressing objects:  46% (10897/23688)   [K
remote: Compressing objects:  47% (11134/23688)   [K
remote: Compressing objects:  48% (11371/23688)   [K
remote: Compressing objects:  49% (11608/23688)   [K
remote: Compressing objects:  50% (11844/23688)   [K
remote: Compressing objects:  51% (12081/23688)   [K
remote: Compressing objects:  52% (12318/23688)   [K
remote: Compressing objects:  53% (12555/23688)   [K
remote: Compressing objects:  54% (12792/23688)   [K
remote: Compressing objects:  55% (13029/23688)   [K
remote: Compressing objects:  56% (13266/23688)   [K
remote: Compressing objects:  57% (13503/23688)   [K
remote: Compressing objects:  58% (13740/23688)   [K
remote: Compressing objects:  59% (13976/23688)   [K
remote: Compressing objects:  60% (14213/23688)   [K
remote: Compressing objects:  61% (14450/23688)   [K
remote: Compressing objects:  62% (14687/23688)   [K
remote: Compressing objects:  63% (14924/23688)   [K
remote: Compressing objects:  64% (15161/23688)   [K
remote: Compressing objects:  65% (15398/23688)   [K
remote: Compressing objects:  66% (15635/23688)   [K
remote: Compressing objects:  67% (15871/23688)   [K
remote: Compressing objects:  68% (16108/23688)   [K
remote: Compressing objects:  69% (16345/23688)   [K
remote: Compressing objects:  70% (16582/23688)   [K
remote: Compressing objects:  71% (16819/23688)   [K
remote: Compressing objects:  72% (17056/23688)   [K
remote: Compressing objects:  73% (17293/23688)   [K

And a progress bar that sits at 0%.

Am I missing something about how to pipe/grep/awk the data from git into dialog, or is this approach just not going to work?

Sean Hagen
  • 752
  • 10
  • 30
  • Most of what I've got I got from [this](http://stackoverflow.com/questions/4062862/git-stderr-output-cant-pipe) question, just trying to replace zenity with dialog --gauge. – Sean Hagen Oct 16 '14 at 18:24
  • the man pages suggest dialog is expecting to get just #s, you might try piping to awk or something to get just the percentages extracted – Andrew C Oct 16 '14 at 18:35
  • @AndrewC that's what the `grep "[0-9]\{1,2\}%" | awk '{print $7}' ` bit is for, but it only seems to run once, instead of continuously grabbing the latest line from the file. – Sean Hagen Oct 16 '14 at 19:33
  • whoops. duh. Try moving it forward in the pipeline before you redirect to the file (after the first pipe and before the first car) ? – Andrew C Oct 16 '14 at 20:35
  • Replace you second `cat` by a `tail -f`. Here you're writing a file in background, and then you show it once only for your dialog. I think that if you want to keep trace of the progress in file you'd better use `tee /tmp/gitprocfile` insteand of the two `cat` calls and have a single line command (unless its on two separate terminals). If the file is not needed at all, just suppress the calls to `cat` and pipe the output of git directly to grep. – Tensibai Oct 17 '14 at 12:34
  • You appear to be a dupe of http://stackoverflow.com/questions/4062862/git-stderr-output-cant-pipe - see the comments and answers there – Andrew C Oct 17 '14 at 13:21

1 Answers1

3

As I think my comment is really too long and unclear here is my udnerstanding:

git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 | cat > /tmp/gitprocfile &

Calling git and writing the output in a file, cat is not necessary here.

cat /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50 

Just after the prvious command, show the file one with cat and dot the grep etc. So you get the content of the file only once ...

If wanting a text output at end I would do:

 git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 | tee /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50

If the dialog is in antoher term than the gitcommand:

In terminal 1:

echo '' > /tmp/gitprocfile; git clone git@github.com:really-bit-git-repo output-dir --progress 2>&1 >> /tmp/gitprocfile &

In terminal 2:

tail -f /tmp/gitprocfile | grep "[0-9]\{1,2\}%" | awk '{print $7}' | dialog --gauge "Progress" 7 50 

I'm not used to dialog, but at least I'm sure your attempt won't reload the file on change.

Tensibai
  • 15,557
  • 1
  • 37
  • 57
  • I can't use 'tail -f' though, this is being used inside a script. I don't want tail to wait forever for new lines, it should exit when the git client finishes. – Sean Hagen Oct 21 '14 at 20:17
  • So use option one, tee to a file to get stout and file, or get rid of the file at all if all append in the same term... – Tensibai Oct 21 '14 at 20:20