Skip to content

Commit

Permalink
improve gw-dev and add gw-devs
Browse files Browse the repository at this point in the history
New version doesn't rely on antiquated Perl.
  • Loading branch information
aspiers committed Nov 7, 2015
1 parent 943376b commit 9fa0258
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
28 changes: 2 additions & 26 deletions bin/gw-dev
@@ -1,27 +1,3 @@
#!/usr/bin/perl
#!/bin/bash

use strict;
use warnings;

use List::Util qw(first);

my @devs = ();
open(ROUTE, "route -n |") or die "fork route -n failed: $!\n";
while(<ROUTE>) {
next unless /^0\.0\.0\.0 /;
my @F = split /\s+/, $_;
push @devs, $F[7];
#warn "# $F[7]\n";
}
close(ROUTE) or die "route -n failed: $!\n";

sub choose_if_valid {
my ($dev) = @_;
return unless $dev;
print "$dev\n";
exit 0;
}

choose_if_valid($devs[0]) if @devs == 1;
choose_if_valid(first { /eth\d/ } @devs);
choose_if_valid($devs[0]);
gw-devs | head -n 1
3 changes: 3 additions & 0 deletions bin/gw-devs
@@ -0,0 +1,3 @@
#!/bin/bash

ip route | ruby -lne 'puts $1 if /^default .* dev (\S+)/'

0 comments on commit 9fa0258

Please sign in to comment.