-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New version doesn't rely on antiquated Perl.
- Loading branch information
Showing
2 changed files
with
5 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
ip route | ruby -lne 'puts $1 if /^default .* dev (\S+)/' |