[SOLVED] Conky and changing the network interface(for whatever it may be).
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Conky and changing the network interface(for whatever it may be).
Hi there,
I'm hoping you can help. I have a conky.conf script which has the network adaptors ie: ${addr eth0 }. I can change the eth0 to whatever I want using sed -e s/eth0/newinterface_here/g oldfile > newfile.
But I want to know how to read whatever the active interface is, this could be for any machine and one of the multiple names. ie: eno1,eth0,em1,ens1, enp2so etc(you get the idea). I only want the active port and not any wireless etc.
Something like: ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'
And then pass the result to 'newinterface_here'
I've tried to write a script but the best I'm getting is that eth0 is removed from the script and not adding eg:'em1'.
Can you help please?
I know I can write multiple adaptors and select the active one but I don't want this. When the script is run I want it to do: 1) This is the adaptor 2)Replace the text eth0 with (1) 3) Write the new file correct for this machine.
so you need a script that can find out what the active device is on any box, cat5 not wifi, then take that and add it to your conky file. I only have wifi but you need to know the command to find the information, then look at its output to figure out where to get what you're looking for
Code:
#output
2: wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
link/ether 00:24:d7:cf:9e:a4 brd ff:ff:ff:ff:ff:ff
#gets my wifi device name holds it in a var.
device="$(ip link | awk '/2:/{print $2}' | rev | cut -c 2- | rev)"
#use double quotes
sed -i "s|eth0|$device|" dave
Code:
#putting it together
device="$(ip link | awk '/2:/{print $2}' | rev | cut -c 2- | rev)" | sed -i "s|eth0|$device|" dave
#before
$ cat dave
obodfdf
eth0 fgds
bogdg
sds
#after
$ cat dave
obodfdf
wlo1 fgds
bogdg
sds
putting it all in one line
Code:
sed -i "s|eth0|$(ip link | awk '/2:/{print $2}' | rev | cut -c 2- | rev)|" dave
with me using ip link, and UP for the check, as there is two up's in the output
Code:
$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
link/ether 00:24:d7:cf:9e:a4 brd ff:ff:ff:ff:ff:ff
#returns
$ device="$(ip link | awk '/UP/{print $2}' | rev | cut -c 2- | rev)" ; echo $device
lo wlo1
but if you cannot work that out, then post back for further assistant.
ip addr | awk '/state UP/ {print $2}' | sed 's/.$//' - This works to get the name(or the text I need).
What I don't have is the correct script. I keep making a hash of everything and need advice.
As I said I have the sed part just about correct, I can manually make the change(as in I can run the sed part in terminal fine). I just need to know what to put in the script.
Code:
#!/bin/bash
INTERFACE="ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'" && sed -e s/eth0/$INTERFACE/g oldfile > newfile
ip addr | awk '/state UP/ {print $2}' | sed 's/.$//' - This works to get the name(or the text I need).
What I don't have is the correct script. I keep making a hash of everything and need advice.
As I said I have the sed part just about correct, I can manually make the change(as in I can run the sed part in terminal fine). I just need to know what to put in the script.
Code:
#!/bin/bash
INTERFACE="ip addr | awk '/state UP/ {print $2}' | sed 's/.$//'" && sed -e s/eth0/$INTERFACE/g oldfile > newfile
what works on the command line. Just put it into a script. that simple.
did you chck your put put of awk ?
then open your test file to see if you're getting the desired results.
this does not need to be a bash script, the file just needs to be executable.
the rev reverse the text gotten, then cut removes the unwanted part the - hyphen removes everything past the start 2 .. you might have to adjust the 2 to whatever works for you. that is if you get more than just the eth0, eth1 etc..
the put it back forwards again by using another rev
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.