J
J
Jahmal Gadhar2018-11-05 20:28:38
linux
Jahmal Gadhar, 2018-11-05 20:28:38

How to get parameters from file for bash script?

A simple example. We have a script that sends the data received from ifconfig to the file
#!/bin/bash
ifconfig >> myfile
echo "Ok"
As a result, we get something like this in the file:
eth0: flags=4163 mtu 1500
inet 0.0.0.0 netmask 0.0.0.0 broadcast 0.0 0.0.0.0 netmask 0.0.0.0 broadcast 0.0.0.0 TX errors 0
dropped 0 overruns 0 carrier 0 collisions 0 eth3: flags=
4163 mtu 1500
inet 0.0.0.0 netmask 0.0.0.0 inet 0.0.0.0 netmask 0.0.0.0 broadcast 0.0.0.0 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Actually the question is: how can I get only the name of the available interfaces?
And is it possible to do without writing data from ifconfig to a file?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Radjah, 2018-11-05
@gogogogo

On the knee
Parsing option:

$ ip l|grep mtu|cut -d":" -f 2
 lo
 eth0
 tun0
 tap0
 br0
 tun10
 tun1

Variant with sysfs:
$ ls /sys/class/net/
br0  eth0  lo  tap0  tun0  tun1  tun10

A
AVKor, 2018-11-05
@AVKor

Actually the question is: how can I get only the name of the available interfaces?

grep
There is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question