Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
dylan-drummond
Contributor
The command-line tool ifconfig (from the 'net-tools' family) has been officially deprecated for years in favour of the ip tool (from the 'iproute2' family). But in practice, since most Linux distros included 'ifconfig' alongside 'ip', so it was not really very deprecated in practice. However, two recently released versions of major distros - openSUSE Leap 15, and Ubuntu 18.04 LTS - do not include ifconfig as part of the base installation anymore.

"So, who should care about that?". Well, if you want to install AS NetWeaver Abap Developer Edition, you might have been following either the SAP official guides (for openSUSE); or, (maybe unlikely) the unofficial rambling guide by me (for Ubuntu):

https://blogs.sap.com/2016/11/03/linux-for-newbies-installing-opensuse-on-oracle-virtualbox/

https://blogs.sap.com/2018/04/05/installing-sap-netweaver-developer-edition-on-an-ubuntu-desktop-vm-...

Now currently (early June 2018 - if the SAP provided script changes to deal with the issue, this blog will become a bit obsolete), so anyway currently, if your VM is Leap 15 or Ubuntu 18.04, your SAP installation script, called install.sh ... will likely fail and exit, providing the error message:

./install.sh: line 77: ifconfig: command not found

So let's see what that line 77 in install.sh is doing:
myip=`ifconfig | egrep "inet addr" | grep Bcast | awk '{ print $2 }' | awk -F ":" '{ print $2 }'`

What happens in this line, is that the bash script tries to execute the 'ifconfig' command, and then parses the output from 'ifconfig' to find the IPv4 address of the host machine on the network. But since your OS (Leap15 or Ubuntu18) doesn't have the 'ifconfig' tool installed, so obviously that is why we get the error message telling us that "ifconfig: command not found".

I suppose there are 3 workarounds for this issue... let's go through them shall we? Ye-ehss we shall 🙂 After that, I give an example script that should cover both pre-2018 as well as 2018-onwards distros (openSUSE and Ubuntu - obviously I have not tested all possible Linux distros, that would be a job for an army not a hobbyist). So, the workarounds...

 

Workaround 1 - run the install.sh script with the option '-s'


So, remember that we always have to execute this script as the root user. Either by elevating ourselves to root, or by sudoing. 'sudo' is generally better practice, but here we will assume you have elevated yourself to root, e.g. by
$ sudo -i

...and you have moved into the relevant directory where the install.sh script is located. Then you can run the script with the "-s" option:
# ./install.sh -s 

The "-s" option skips checking the validity of the hostname, so it skips over line 77. So that is the simple workaround... but you know, with a programming background, with a pedantic mentality, you...ok... I... we?... yes, we... we don't like any workaround that says "avoid executing that block of code, because it crashes"... and if there is code that helps you by checking up on your chosen hostname (and as it happens, also on your hosts file config), so IMAO the more checks we pass rather than avoid, the better the chances for a successful installation... and so, we come to the second workaround, which at first might seem quite neat, until we find out it is not quite ideal...

 

Workaround 2 - install the 'ifconfig'-program... and change the install.sh script


So the error message is saying that ifconfig isn't found... And that is correct. So in openSUSE Leap 15, we first locate the package we need:
$ cnf ifconfig



So there you go, a nice easy command to get ifconfig back:
$ sudo zypper install net-tools-deprecated

With Ubuntu 18.04, we get told straight away what we need to do to get our old program back:



So our command to get ifconfig and the other net-tools back is:
$ sudo apt install net-tools

... so, now we have ifconfig back, great, we can be dinosaurs with our 20th Century tools 🙂 But there is a fly in the ointment... the output format of ifconfig has changed (even though this tool is deprecated) in both Leap 15 and Ubuntu 18.04 ... so our install.sh script runs, but finds the empty set by parsing ifconfig's output incorrectly, and this empty value then fails to match the IP address we get by pinging our hostname (mapping to IPv4 address you should have already set in /etc/hosts file).

So, installing 'ifconfig' is not enough. Instead, what we can do is analyse the old-school and new-school output of 'ifconfig', to work out a new line to parse 'ifconfig'...

Let's examine Ubuntu 16.04 vs Ubuntu 18.04 (in fact, though not described here, the "openSUSE 42.3 vs Leap 15" case is very similar, just bear in mind that these openSUSE distros insist on 'sudo' for ifconfig)... So, In Ubuntu 16.04, 'ifconfig' gives us this kind of output (I included a command before 'ifconfig', just to reassure you that the version is what I said it is 🙂 😞



You can see there, that to get hold of the IPv4 address-string "10.0.2.15", the install.sh line 77 is correct:
myip=`ifconfig | egrep "inet addr" | grep Bcast | awk '{ print $2 }' | awk -F ":" '{ print $2 }'`

we execute 'ifconfig', then we find all lines containing the substring "inet addr", then we pick only the line which contains the substring "Bcast", because that is an indicator that it is not the localhost address but a real network node address, then we take the second substring of this line, which is "addr:10.0.2.15" and then we split that string using ":" as our separator, and keep the second part of the splitting, i.e. "10.0.2.15".

Now let's look at the output of 'ifconfig' on Ubuntu 18.04:



So, we need to work out which magic spells to cast on the terminal, to get the string "10.0.2.15" from that output... Well, our line doesn't have "inet addr" anymore, but it does have "inet", and it doesn't have "Bcast" anymore, but it does have "broadcast"... and, if we get the second substring from that line, then we are done... quick test:



So there we go, we have our new line 77:
myip=`ifconfig | egrep "inet" | grep broadcast | awk '{ print $2 }'`

Before we go modifying the SAP supplied install.sh, let's make a backup copy:
# cp install.sh install.sh.bak

Then depending on your editor usage preferences and/or editor availability ('nano' is more Ubuntu-centric), you might e.g. use one of these
# nano install.sh

# vi install.sh

... you comment out the old line, you add in the new line, you save the script, and then you test it, by executing the script as root:
# ./install.sh

Now your variable "myip" will contain the IP address found by ifconfig, just like in the good old days, and hopefully that then matches the result of pinging your hostname, and the script confirms that hostname looks compliant and you can continue with the installation.

Note, though, that you are having to do both install deprecated tools, and modify the install.sh script. So it's a bit, I would say, untidy. Never mind though, there is a neater workaround coming up...

 

Workaround 3 - replace line 77 with a line that parses the output of the ip-command


So it is not actually necessary to install 'ifconfig', which is anyway deprecated. For about the last 15 years, all distros have included the iproute2 family of tools, which includes the program called 'ip'. And you can make a minor change to your install script, to use 'ip' instead of 'ifconfig'.

[I am not getting involved in the debate about whether it was a good idea to deprecate one set of tools; we just need to be practical and accept that this deprecation is really starting to arrive in Linux].

So, here is an example of what the output of:
$ ip addr show

looks like:



Once again we can muck around on the command line to get some idea of how this output should be parsed to get the IPv4 address (in this case, it is 10.0.2.15)... we need all lines with substring "inet"; the one with the substring "brd" (as in "broadcast" but pithier) is our line... if we take the second string on that line, it is e.g. "10.0.2.15/24" (indicating that we are on a subnet where all addresses begin "10.0.2", since that is 24 of the available 32 bits specified), anyway we make "/" the separator and take the first of the two substrings it separates:



So there we go, we have our new line 77:
myip=`ip addr show | grep inet | grep brd | awk '{ print $2 }' | awk -F "/" '{ print $1 }'`

Before we go modifying the SAP supplied install.sh, let's make a backup copy:
# cp install.sh install.sh.bak

Then depending on your editor usage preferences and/or editor availability ('nano' is more Ubuntu-centric), you might e.g. use one of these
# nano install.sh

# vi install.sh

... you comment out the old line, you add in the new line, you save it, and then you test it. If the test works, the hostname check will run in the correct manner again, which is nice.

 

Example of how to modify the script to use 'ip' preferably, but otherwise to pick the suitable output format of 'ifconfig'


This example is maybe overkill, but anyway, here is what it does: first it checks to see if we can use the 'ip' command - if so, we use it, and so that is more or less all there is to say; if for some odd reason our distro does not have 'ip' available as an executable program, then we first do an "output test" with ifconfig, so that we can have a reasonable chance of picking the right "parser" chain of commands after 'ifconfig', either old-school (grep "inet addr"...) or new-school (grep inet | grep broadcast...).

Tested this on 4 distros (Leap 42.3, Leap 15; Ubuntu 16.04.4, Ubuntu 18.04). I admit that I took a shortcut for testing the 'ifconfig' block of code, by changing the line:
if [ -x "$(command -v ip)" ]; then

to:
if [ -x "$(command -v ipanema)" ]; then

... the idea being, that since i do not have any program or program-alias called 'ipanema', so this is a kind of beach-football relaxed way to get code coverage of the 'ifconfig' block under "elif...". Obviously if you were getting paid to test new scripts, rather than writing them as a slightly strange activity in your free time, you wouldn't take such blatant shortcuts, rather you would uninstall 'ip' on the test VM, and so on 🙂

Ah yes, the sample code, here it is... if I pasted the wrong version, or there is some bug in there I should have caught but didn't, then let me know, happy to make any sensible corrections!
#  marmot: Begin change-2018-06-10-001 ##########
# The old code used deprecated program 'ifconfig', and that program's outdated (since e.g. openSUSE Leap 15 and Ubuntu 18.04 LTS) output-format.
# ### Replaced code (one line, commented out below):
# myip=`ifconfig | egrep "inet addr" | grep Bcast | awk '{ print $2 }' | awk -F ":" '{ print $2 }'`
# ### End of replaced code ###
# This changed code prefers the program 'ip' from the 'iproute2' family; if not available, we look for 'ifconfig' and try to work out the output format to be parsed...
if [ -x "$(command -v ip)" ]; then
echo "The command-program 'ip' was found, using that to find the IPv4 address on the main network..."
myip=`ip addr show | grep inet | grep brd | awk '{ print $2 }' | awk -F "/" '{ print $1 }'`
elif [ -x "$(command -v ifconfig)" ]; then
echo "The command-program 'ifconfig' was found, using that to find the IPv4 address on the main network..."
# oldifconfig= `ifconfig | egrep "inet addr"` #<-only valid syntax in some cases
oldifconfig=$(ifconfig | grep "inet addr")
# echo "oldifconfig" $oldifconfig "...banzai!!"
if [ -n "$oldifconfig" ]; then
echo "Using old-school 'ifconfig' output ('inet addr ... Bcast ...') as the basis for parsing the IPv4 address..."
myip=`ifconfig | egrep "inet addr" | grep Bcast | awk '{ print $2 }' | awk -F ":" '{ print $2 }'`
else
echo "Using new-school 'ifconfig' output ('inet ... broadcast ...') as the basis for parsing the IPv4 address..."
myip=`ifconfig | egrep "inet" | grep broadcast | awk '{ print $2 }'`
fi
else
echo "You need either the command-program called 'ip', or at least the deprecated command-program 'ifconfig', in case you want to check the IP-address matches between what the network interface believes is this host's address, and what the ping of the hostname (mapped in /etc/hosts) brings back."
echo "In SUSE distros, you can install 'ifconfig' using: 'sudo zypper install net-tools-deprecated'"
echo "In Ubuntu, you can install 'ifconfig' using: 'sudo apt install net-tools'"
exit 1
fi
# marmot: EndOf change-2018-06-10-001 ##########

Have a nice day now everyone!

 
7 Comments
Labels in this area