On Sun, Aug 23, 2020 at 3:23 AM ToddAndMargo via users <users@xxxxxxxxxxxxxxxxxxxxxxx> wrote: > On 2020-08-22 02:53, Tom H wrote: >> 1) Why do you use "$InetDev" in GetIP and "eno2 in GetGW and >> UpDownedEthernetDevices? > > Because I screwed up. Good catch. If $INetDev had changed, > I would have had some troubleshooting to do! I fixed. :) >> 2) Why do you use "-i" for grep in GetIP? > > "-i" is case insensitive. Do do it out of habit. Makes > so I don't have to constantly wonder about the case. > > I use the method ".lc" in Raku (Perl 6) all the time for > the same reason. I just don't trust the case. > > When I am careening through web pages, I often > find the web developer will change case on me at > times. So I plan for him. >> 3) Why do you use "sed -n 1,1p" in GetGW? > > Because I only wanted the first line. Sometimes > with that commend you get two lines back. I am > covering all my bases. In the unlikely event that you have two UGs on eno2, you must want both, no? >> 4) Why do you use "route" in GetGW when you're using "ip" elsewhere >> and "net-tools" isn't installed by default? > > I like to mixed up all the different way of doing things. > Sort of like showing alternate examples as I go >> Use of awk >> >> 1) "grep search | awk {...}" is the same as "awk '/search/ {...}" >> >> 2) "grep search1 | grep search2 | awk {...}" is the same as "awk >> '/search1/ && /search2/ {...}" > > I have a cheat sheet of awk examples. I tend to use what I remember > first though. I should learn the "search" property > and stick it in the sheet. Problem is that I am migrating > away from bash and into Raku (Perl 6) as I have a bazillion > times more power in Raku. And Raku is just plain fun to > program in. > > I should post these things here more often. You are a great > second pair of eyes! :) > Here is my latest: > > This is from another program. I find it almost impossible > to find my gateway if the device is down. In the program, > all the devices need to be up anyway, so I up anyone that > is down. I use both "device" and "connection" as I > find that if cone does not work, the other will. I also > "down" first as sometimes I have found "up" error out > on me if I don't first down. So, I am covering my bases. > > function UpDownedEthernetDevices () { > > local State="" > local LinkState="" > > for Line in $(nmcli device | grep ethernet | awk '{print $1}'); do > State="$(nmcli device | grep $Line | awk '{print $3}')" > LinkState="$(ip address | grep eno2 | awk -F "," '{print $3}')" > # echo "Line = <$Line> State = <$State> LinkState = > <$LinkState>')" > "/dev/tty" > > if [ "$State" == "disconnected" ]; then > echo "Reconnecting $Line" > "/dev/tty" > /usr/bin/nmcli device disconnect $Line > /usr/bin/nmcli device connect $Line > /usr/bin/nmcli connection down $Line > /usr/bin/nmcli connection up $Line > > elif [[ $LinkState == "DOWN" ]]; then > echo "Reattaching (link) $Line" > "/dev/tty" > beesu "ip link set $Line down; ip link set $Line up;" > > echo "Reconnecting $Line" > "/dev/tty" > /usr/bin/nmcli connection down $Line > /usr/bin/nmcli connection up $Line > fi > done > } You're using eno2 rather than a variable. Why do you need "beesu" for "ip" and not for "nmcli"? _______________________________________________ users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx