diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-12-22 14:10:29 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-12-22 14:29:50 -0800 |
commit | ddca45d3dc93847d619adc0788cd631e786c6a24 (patch) | |
tree | 57d659852aa7f91c4df85acd9f14e882cd800184 | |
parent | 0daff396c78a958aba097db5d7d91e37678b9f5a (diff) | |
download | vyatta-op-ddca45d3dc93847d619adc0788cd631e786c6a24.tar.gz vyatta-op-ddca45d3dc93847d619adc0788cd631e786c6a24.zip |
Use perl to read resolv.conf
Don't need to use grep to parse resolv.conf, perl is simpler
and more powerful.
-rwxr-xr-x | scripts/vyatta-show-dhclient.pl | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/scripts/vyatta-show-dhclient.pl b/scripts/vyatta-show-dhclient.pl index 3ec4b8b..9a3ea74 100755 --- a/scripts/vyatta-show-dhclient.pl +++ b/scripts/vyatta-show-dhclient.pl @@ -71,6 +71,17 @@ sub dhclient_parse_vars { return %var_list; } +# Get current domain (if any) defined in resolv.conf +sub resolve_domain { + open (my $rc, '<', '/etc/resolv.conf') + or return; + + while (<$rc>) { + next unless m/^domain (\S+)/; + return $1; + } +} + sub dhclient_show_lease { my ($file) = @_; @@ -108,27 +119,14 @@ sub dhclient_show_lease { } } print "subnet mask: $new_subnet_mask\n" if defined $new_subnet_mask; - if (defined $new_domain_name) { - print "domain name: $new_domain_name"; - my $cli_domain_overrides = 0; - my $if_domain_exists = `grep domain /etc/resolv.conf 2> /dev/null | wc -l`; - if ($if_domain_exists > 0) { - my @domain = `grep domain /etc/resolv.conf`; - for my $each_domain_text_found (@domain) { - my @domain_text_split = split(/\t/, $each_domain_text_found, 2); - my $domain_at_start_of_line = $domain_text_split[0]; - chomp $domain_at_start_of_line; - if ($domain_at_start_of_line eq "domain") { - $cli_domain_overrides = 1; - } - } - } - if ($cli_domain_overrides == 1) { - print "\t[overridden by domain-name set using CLI]\n"; - } else { + if ($new_domain_name) { + print "domain name: $new_domain_name"; + my $cur_domain = resolve_doman(); + print "\t[overridden by domain-name set using CLI]" + if (defined $cur_domain && $cur_domain ne $new_domain_name); print "\n"; - } } + print "router : $new_routers\n" if defined $new_routers; print "name server: $new_domain_name_servers\n" if defined $new_domain_name_servers; |