Kasemodder has asked for the wisdom of the Perl Monks concerning the following question:
What I end up getting however, does not match the expected result.#!/usr/bin/perl chomp($syshost = `hostname`); chomp($sysip = `ifconfig | grep -i inet | egrep -v "inet6|127. +0.0.1" | head -n 1 | awk '{print $2}'`); chomp($sysnm = `ifconfig | grep -i inet | egrep -v "inet6|127. +0.0.1" | head -n 1 | awk '{print $4}'`); print "hostname : $syshost\n"; print "IP : $sysip\n"; print "Netmask : $sysnm\n";
If I run the commands in the ` ` sections within my bash shell, I do get the expected result, but with the script, I do not. I've seen some stuff about awk and perl not getting along but it's what I know, and I'm in a bind with inherited code (with 0 comments), a language I am unfamiliar with, and tight deadlines, so any pointers into the right direction would be appreciated.EXPECTED RESULT hostname : laptop.example.com IP : 10.10.50.21 Netmask : 255.255.255.0 RECEIVED RESULT hostname : laptop.example.com IP : inet 10.10.50.21 netmask 255.255.255.0 destination 1 +0.10.50.1 Netmask : inet 10.10.50.21 netmask 255.255.255.0 destinat +ion 10.10.50.1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extracting network information
by 1nickt (Canon) on Sep 01, 2015 at 17:17 UTC | |
by Kasemodder (Initiate) on Sep 01, 2015 at 18:41 UTC | |
|
Re: Extracting network information
by hippo (Archbishop) on Sep 01, 2015 at 17:14 UTC | |
by Kasemodder (Initiate) on Sep 01, 2015 at 18:34 UTC | |
|
Re: Extracting network information (with CPAN modules)
by 1nickt (Canon) on Sep 01, 2015 at 17:45 UTC | |
|
Re: Extracting network information
by stevieb (Canon) on Sep 01, 2015 at 17:29 UTC |