Hi All,
What am I doing wrong here? nmcli says eno2 is disconnected but is working as if it was connected.
eno2 is my (only) Internet connection.
$ nmcli device status | grep -i eno2 eno2 ethernet disconnected --
$ ping -c 1 -I eno2 8.8.8.8 PING 8.8.8.8 (8.8.8.8) from 192.168.250.135 eno2: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.0 ms
Huh? I am confused.
Many thanks, -T
On Mon, Aug 17, 2020 at 11:38 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
What am I doing wrong here? nmcli says eno2 is disconnected but is working as if it was connected.
eno2 is my (only) Internet connection.
$ nmcli device status | grep -i eno2 eno2 ethernet disconnected --
$ ping -c 1 -I eno2 8.8.8.8 PING 8.8.8.8 (8.8.8.8) from 192.168.250.135 eno2: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.0 ms
Without more information, the above must mean that eno2 isn't configured by NM.
On 2020-08-17 07:25, Tom H wrote:
On Mon, Aug 17, 2020 at 11:38 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
What am I doing wrong here? nmcli says eno2 is disconnected but is working as if it was connected.
eno2 is my (only) Internet connection.
$ nmcli device status | grep -i eno2 eno2 ethernet disconnected --
$ ping -c 1 -I eno2 8.8.8.8 PING 8.8.8.8 (8.8.8.8) from 192.168.250.135 eno2: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.0 ms
Without more information, the above must mean that eno2 isn't configured by NM.
The error is random.
$ /usr/bin/nmcli c up eno2 clears the error
$ cat /etc/sysconfig/network-scripts/ifcfg-eno2 TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no # NAME=enp7s0 NAME=eno2 UUID=a056777e-8a75-4da5-9585-6aacf150b862 DEVICE=eno2 ONBOOT=yes # PEERDNS=yes PEERDNS=no PEERROUTES=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes DNS1=127.0.0.1 USERCTL=yes
Do you need any other information.
On 2020-08-17 12:50, ToddAndMargo via users wrote:
On 2020-08-17 07:25, Tom H wrote:
On Mon, Aug 17, 2020 at 11:38 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
What am I doing wrong here? nmcli says eno2 is disconnected but is working as if it was connected.
eno2 is my (only) Internet connection.
$ nmcli device status | grep -i eno2 eno2 ethernet disconnected --
$ ping -c 1 -I eno2 8.8.8.8 PING 8.8.8.8 (8.8.8.8) from 192.168.250.135 eno2: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.0 ms
Without more information, the above must mean that eno2 isn't configured by NM.
The error is random.
$ /usr/bin/nmcli c up eno2 clears the error
$ cat /etc/sysconfig/network-scripts/ifcfg-eno2 TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no # NAME=enp7s0 NAME=eno2 UUID=a056777e-8a75-4da5-9585-6aacf150b862 DEVICE=eno2 ONBOOT=yes # PEERDNS=yes PEERDNS=no PEERROUTES=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes DNS1=127.0.0.1 USERCTL=yes
Do you need any other information?
I added NM_CONTROLLED=yes to my ifcfg-eno2. But I think it is the default
On Mon, Aug 17, 2020 at 9:50 PM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-17 07:25, Tom H wrote:
On Mon, Aug 17, 2020 at 11:38 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
What am I doing wrong here? nmcli says eno2 is disconnected but is working as if it was connected.
eno2 is my (only) Internet connection.
$ nmcli device status | grep -i eno2 eno2 ethernet disconnected --
$ ping -c 1 -I eno2 8.8.8.8 PING 8.8.8.8 (8.8.8.8) from 192.168.250.135 eno2: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.0 ms
Without more information, the above must mean that eno2 isn't configured by NM.
The error is random.
$ /usr/bin/nmcli c up eno2 clears the error
It'd be worrying if bringing the "eno2" connection up didn't make the "eno2" nic connected.
$ cat /etc/sysconfig/network-scripts/ifcfg-eno2 TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no # NAME=enp7s0 NAME=eno2 UUID=a056777e-8a75-4da5-9585-6aacf150b862 DEVICE=eno2 ONBOOT=yes # PEERDNS=yes PEERDNS=no PEERROUTES=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes DNS1=127.0.0.1 USERCTL=yes
Do you need any other information.
Thanks. It looks OK. What would be interesting would be "nmcli d sh eno2" and "nmcli c sh eno2" when you get that error.
On 2020-08-17 02:38, ToddAndMargo via users wrote:
Hi All,
What am I doing wrong here? nmcli says eno2 is disconnected but is working as if it was connected.
eno2 is my (only) Internet connection.
$ nmcli device status | grep -i eno2 eno2 ethernet disconnected --
$ ping -c 1 -I eno2 8.8.8.8 PING 8.8.8.8 (8.8.8.8) from 192.168.250.135 eno2: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.0 ms
Huh? I am confused.
Many thanks, -T
oh and it gets even screwier:
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
$ /usr/bin/nmcli connection down eno2 Connection 'eno2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
$ nmcli device | grep eno2 eno2 ethernet disconnected --
$ ping -c 1 8.8.8.8 ping: connect: Network is unreachable
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
"UP" ??? On what planet?
On 2020-08-19 14:09, ToddAndMargo via users wrote:
On 2020-08-17 02:38, ToddAndMargo via users wrote:
Hi All,
What am I doing wrong here? nmcli says eno2 is disconnected but is working as if it was connected.
eno2 is my (only) Internet connection.
$ nmcli device status | grep -i eno2 eno2 ethernet disconnected --
$ ping -c 1 -I eno2 8.8.8.8 PING 8.8.8.8 (8.8.8.8) from 192.168.250.135 eno2: 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.0 ms
Huh? I am confused.
Many thanks, -T
oh and it gets even screwier:
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
$ /usr/bin/nmcli connection down eno2 Connection 'eno2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
$ nmcli device | grep eno2 eno2 ethernet disconnected --
$ ping -c 1 8.8.8.8 ping: connect: Network is unreachable
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
"UP" ??? On what planet?
I just created:
ifconfig reports network status incorrectly https://bugzilla.redhat.com/show_bug.cgi?id=1870370
On 2020-08-20 05:28, ToddAndMargo via users wrote:
oh and it gets even screwier:
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
$ /usr/bin/nmcli connection down eno2 Connection 'eno2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
$ nmcli device | grep eno2 eno2 ethernet disconnected --
$ ping -c 1 8.8.8.8 ping: connect: Network is unreachable
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
"UP" ??? On what planet?
I just created:
ifconfig reports network status incorrectly https://bugzilla.redhat.com/show_bug.cgi?id=1870370
NOTABUG
ifconfig, as well as "ip link", are showing the status at the OSI Link Layer.
If you were to pull the cable you'd see.
[egreshko@meimei ~]$ ip link show enp2s0 2: enp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
On 2020-08-19 14:54, Ed Greshko wrote:
On 2020-08-20 05:28, ToddAndMargo via users wrote:
oh and it gets even screwier:
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
$ /usr/bin/nmcli connection down eno2 Connection 'eno2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
$ nmcli device | grep eno2 eno2 ethernet disconnected --
$ ping -c 1 8.8.8.8 ping: connect: Network is unreachable
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
"UP" ??? On what planet?
I just created:
ifconfig reports network status incorrectly https://bugzilla.redhat.com/show_bug.cgi?id=1870370
NOTABUG
ifconfig, as well as "ip link", are showing the status at the OSI Link Layer.
If you were to pull the cable you'd see.
[egreshko@meimei ~]$ ip link show enp2s0 2: enp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
Hi Ed,
Indeed! I mistook the meaning of "UP". Thank you! I just cancelled the bug report.
# ifconfig eno2 down
# ip link show eno2 2: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN
# nmcli device | grep eno2 eno2 ethernet unavailable --
# ifconfig eno2 up
# nmcli device | grep eno2 eno2 ethernet connected eno2
You would not happen to know if there is a command like ifconfig eno2 down that does not require root privileges?
-T
On 2020-08-20 06:24, ToddAndMargo via users wrote:
You would not happen to know if there is a command like ifconfig eno2 down that does not require root privileges?
There is none. Best to configure sudo for that purpose.
Also, I thought it would have happened already, ifconfig is considered "obsolete" and will/may at some point be removed. Best to start using "ip".
On Wed, Aug 19, 2020 at 11:09 PM ToddAndMargo via users users@lists.fedoraproject.org wrote:
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
$ /usr/bin/nmcli connection down eno2 Connection 'eno2' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
$ nmcli device | grep eno2 eno2 ethernet disconnected --
$ ping -c 1 8.8.8.8 ping: connect: Network is unreachable
$ ifconfig | grep eno2 eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
"UP" ??? On what planet?
On this one. A NIC can be "UP" and unconfigured.
"nmcli c" acts on the network layer, like "ip a".
"nmcli d" acts on the data link layer, like "ip l".
On 2020-08-19 19:58, Samuel Sieb wrote:
On 8/19/20 3:24 PM, ToddAndMargo via users wrote:
You would not happen to know if there is a command like ifconfig eno2 down that does not require root privileges?
Haven't we already done this one not long ago? Use "nmcli". nmcli d disconnect eno2
That was the c command previously.
Are all nmcli command able to run as a user?
On 8/20/20 7:04 PM, ToddAndMargo via users wrote:
On 2020-08-19 19:58, Samuel Sieb wrote:
On 8/19/20 3:24 PM, ToddAndMargo via users wrote:
You would not happen to know if there is a command like ifconfig eno2 down that does not require root privileges?
Haven't we already done this one not long ago? Use "nmcli". nmcli d disconnect eno2
That was the c command previously.
Yes, but I was referring to the general use of "nmcli" instead of the various other root-required tools.
Are all nmcli command able to run as a user?
I think so, although I don't know if being in the "wheel" group makes a difference.
On 2020-08-21 10:35, Samuel Sieb wrote:
On 8/20/20 7:04 PM, ToddAndMargo via users wrote:
On 2020-08-19 19:58, Samuel Sieb wrote:
On 8/19/20 3:24 PM, ToddAndMargo via users wrote:
You would not happen to know if there is a command like ifconfig eno2 down that does not require root privileges?
Haven't we already done this one not long ago? Use "nmcli". nmcli d disconnect eno2
That was the c command previously.
Yes, but I was referring to the general use of "nmcli" instead of the various other root-required tools.
Are all nmcli command able to run as a user?
I think so, although I don't know if being in the "wheel" group makes a difference.
We went through that a while back as well. It is determined by polkit. Wheel is not needed. The type terminal session does matter though.
I think almost all commands don't need root. Sadly, I can't recall the command to interrogate polkit rules.
Followup: I create a number of bash functions to handle the task(s). Thank you all for the help!
function GetIP () { echo "$(ip -f inet route | grep -i $InetDev | grep -i src | awk '{print $9}')" }
function CheckInternetStatus () { local GoogleDNS="8.8.8.8"; local RtnStr="$( ping -W .1 -c 1 $GoogleDNS | grep loss );" # echo "RtnStatus = <$?> RtnStr = <$RtnStr>" > "/dev/tty" if [[ "$RtnStr" == *", 0% packet loss"* ]]; then echo "UP" else echo "DOWN" fi }
function GetPublicIP () { local WIP=$(dig +short myip.opendns.com @resolver1.opendns.com) # echo "WIP = <$WIP>" > "/dev/tty" if [[ "$WIP" == *"not found"* || "$WIP" == *"no servers could be reached"* ]]; then WIP="Not Found" fi
echo $WIP }
function GetGW () { echo "$(route -n | grep eno2 | grep UG | sed -n 1,1p | awk '{print $2}')" }
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 }
function DisplayStatus () { NotifySound
local Msg="" local GW="" local IP="" local InternetStatus="$(CheckInternetStatus)" local PublicIP=""
# if [ -n "$(netstat -rn | grep -i $InetDev | grep -i UG)" ]; then if [ "$InternetStatus" == "UP" ]; then GW="$(GetGW)" IP="$(GetIP)" PublicIP="$(GetPublicIP)"
# Msg+="$InetDev successfully started and is a gateway\n\n" Msg+="Internet is $InternetStatus\n" Msg+="IP=$IP\n" Msg+="gw=$GW\n" Msg+="Public IP=$PublicIP\n"
echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=250
else Msg="Internet ($InetDev) is down" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=200 fi }
On Sat, Aug 22, 2020 at 1:57 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
Followup: I create a number of bash functions to handle the task(s). Thank you all for the help!
function GetIP () { echo "$(ip -f inet route | grep -i $InetDev | grep -i src | awk '{print $9}')" }
function CheckInternetStatus () { local GoogleDNS="8.8.8.8"; local RtnStr="$( ping -W .1 -c 1 $GoogleDNS | grep loss );" # echo "RtnStatus = <$?> RtnStr = <$RtnStr>" > "/dev/tty" if [[ "$RtnStr" == *", 0% packet loss"* ]]; then echo "UP" else echo "DOWN" fi }
function GetPublicIP () { local WIP=$(dig +short myip.opendns.com @resolver1.opendns.com) # echo "WIP = <$WIP>" > "/dev/tty" if [[ "$WIP" == *"not found"* || "$WIP" == *"no servers could be reached"* ]]; then WIP="Not Found" fi
echo $WIP}
function GetGW () { echo "$(route -n | grep eno2 | grep UG | sed -n 1,1p | awk '{print $2}')" }
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}
function DisplayStatus () { NotifySound
local Msg="" local GW="" local IP="" local InternetStatus="$(CheckInternetStatus)" local PublicIP="" # if [ -n "$(netstat -rn | grep -i $InetDev | grep -i UG)" ]; then if [ "$InternetStatus" == "UP" ]; then GW="$(GetGW)" IP="$(GetIP)" PublicIP="$(GetPublicIP)" # Msg+="$InetDev successfully started and is a gateway\n\n" Msg+="Internet is $InternetStatus\n" Msg+="IP=$IP\n" Msg+="gw=$GW\n" Msg+="Public IP=$PublicIP\n" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=250 else Msg="Internet ($InetDev) is down" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=200 fi}
Without looking at what your functions are actually doing:-
Things that I don't understand:
1) Why do you use "$InetDev" in GetIP and "eno2 in GetGW and UpDownedEthernetDevices?
2) Why do you use "-i" for grep in GetIP?
3) Why do you use "sed -n 1,1p" in GetGW?
4) Why do you use "route" in GetGW when you're using "ip" elsewhere and "net-tools" isn't installed by default?
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/ {...}"
On Sat, Aug 22, 2020 at 11:53 AM Tom H tomh0665@gmail.com wrote:
On Sat, Aug 22, 2020 at 1:57 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
Followup: I create a number of bash functions to handle the task(s). Thank you all for the help!
function GetIP () { echo "$(ip -f inet route | grep -i $InetDev | grep -i src | awk '{print $9}')" }
function CheckInternetStatus () { local GoogleDNS="8.8.8.8"; local RtnStr="$( ping -W .1 -c 1 $GoogleDNS | grep loss );" # echo "RtnStatus = <$?> RtnStr = <$RtnStr>" > "/dev/tty" if [[ "$RtnStr" == *", 0% packet loss"* ]]; then echo "UP" else echo "DOWN" fi }
function GetPublicIP () { local WIP=$(dig +short myip.opendns.com @resolver1.opendns.com) # echo "WIP = <$WIP>" > "/dev/tty" if [[ "$WIP" == *"not found"* || "$WIP" == *"no servers could be reached"* ]]; then WIP="Not Found" fi
echo $WIP}
function GetGW () { echo "$(route -n | grep eno2 | grep UG | sed -n 1,1p | awk '{print $2}')" }
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}
function DisplayStatus () { NotifySound
local Msg="" local GW="" local IP="" local InternetStatus="$(CheckInternetStatus)" local PublicIP="" # if [ -n "$(netstat -rn | grep -i $InetDev | grep -i UG)" ]; then if [ "$InternetStatus" == "UP" ]; then GW="$(GetGW)" IP="$(GetIP)" PublicIP="$(GetPublicIP)" # Msg+="$InetDev successfully started and is a gateway\n\n" Msg+="Internet is $InternetStatus\n" Msg+="IP=$IP\n" Msg+="gw=$GW\n" Msg+="Public IP=$PublicIP\n" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=250 else Msg="Internet ($InetDev) is down" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=200 fi}
Without looking at what your functions are actually doing:-
Things that I don't understand:
- Why do you use "$InetDev" in GetIP and "eno2 in GetGW and
UpDownedEthernetDevices?
Why do you use "-i" for grep in GetIP?
Why do you use "sed -n 1,1p" in GetGW?
Why do you use "route" in GetGW when you're using "ip" elsewhere
and "net-tools" isn't installed by default?
Use of awk
"grep search | awk {...}" is the same as "awk '/search/ {...}"
"grep search1 | grep search2 | awk {...}" is the same as "awk
'/search1/ && /search2/ {...}"
Forgot
5) Why do you use "/usr/bin/nmcli" 6 times and "nmcli" twice? There's no need for absolute paths.
On 2020-08-22 05:25, Tom H wrote:
On Sat, Aug 22, 2020 at 11:53 AM Tom H tomh0665@gmail.com wrote:
On Sat, Aug 22, 2020 at 1:57 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
Followup: I create a number of bash functions to handle the task(s). Thank you all for the help!
function GetIP () { echo "$(ip -f inet route | grep -i $InetDev | grep -i src | awk '{print $9}')" }
function CheckInternetStatus () { local GoogleDNS="8.8.8.8"; local RtnStr="$( ping -W .1 -c 1 $GoogleDNS | grep loss );" # echo "RtnStatus = <$?> RtnStr = <$RtnStr>" > "/dev/tty" if [[ "$RtnStr" == *", 0% packet loss"* ]]; then echo "UP" else echo "DOWN" fi }
function GetPublicIP () { local WIP=$(dig +short myip.opendns.com @resolver1.opendns.com) # echo "WIP = <$WIP>" > "/dev/tty" if [[ "$WIP" == *"not found"* || "$WIP" == *"no servers could be reached"* ]]; then WIP="Not Found" fi
echo $WIP}
function GetGW () { echo "$(route -n | grep eno2 | grep UG | sed -n 1,1p | awk '{print $2}')" }
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}
function DisplayStatus () { NotifySound
local Msg="" local GW="" local IP="" local InternetStatus="$(CheckInternetStatus)" local PublicIP="" # if [ -n "$(netstat -rn | grep -i $InetDev | grep -i UG)" ]; then if [ "$InternetStatus" == "UP" ]; then GW="$(GetGW)" IP="$(GetIP)" PublicIP="$(GetPublicIP)" # Msg+="$InetDev successfully started and is a gateway\n\n" Msg+="Internet is $InternetStatus\n" Msg+="IP=$IP\n" Msg+="gw=$GW\n" Msg+="Public IP=$PublicIP\n" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=250 else Msg="Internet ($InetDev) is down" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=200 fi}
Without looking at what your functions are actually doing:-
Things that I don't understand:
- Why do you use "$InetDev" in GetIP and "eno2 in GetGW and
UpDownedEthernetDevices?
Why do you use "-i" for grep in GetIP?
Why do you use "sed -n 1,1p" in GetGW?
Why do you use "route" in GetGW when you're using "ip" elsewhere
and "net-tools" isn't installed by default?
Use of awk
"grep search | awk {...}" is the same as "awk '/search/ {...}"
"grep search1 | grep search2 | awk {...}" is the same as "awk
'/search1/ && /search2/ {...}"
Forgot
- Why do you use "/usr/bin/nmcli" 6 times and "nmcli" twice? There's
no need for absolute paths.
Missed that. Now they are all absolute paths. Good catch. Thank you!
I use absolute paths when I will sometimes be operating outside the shell. It is a habit of mine to not trust $PATH from the shell. I do it all the time as a "just in case".
I will go over the other four questions in a little bit.
On 2020-08-22 02:53, Tom H wrote:
On Sat, Aug 22, 2020 at 1:57 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
Followup: I create a number of bash functions to handle the task(s). Thank you all for the help!
function GetIP () { echo "$(ip -f inet route | grep -i $InetDev | grep -i src | awk '{print $9}')" }
function CheckInternetStatus () { local GoogleDNS="8.8.8.8"; local RtnStr="$( ping -W .1 -c 1 $GoogleDNS | grep loss );" # echo "RtnStatus = <$?> RtnStr = <$RtnStr>" > "/dev/tty" if [[ "$RtnStr" == *", 0% packet loss"* ]]; then echo "UP" else echo "DOWN" fi }
function GetPublicIP () { local WIP=$(dig +short myip.opendns.com @resolver1.opendns.com) # echo "WIP = <$WIP>" > "/dev/tty" if [[ "$WIP" == *"not found"* || "$WIP" == *"no servers could be reached"* ]]; then WIP="Not Found" fi
echo $WIP}
function GetGW () { echo "$(route -n | grep eno2 | grep UG | sed -n 1,1p | awk '{print $2}')" }
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}
function DisplayStatus () { NotifySound
local Msg="" local GW="" local IP="" local InternetStatus="$(CheckInternetStatus)" local PublicIP="" # if [ -n "$(netstat -rn | grep -i $InetDev | grep -i UG)" ]; then if [ "$InternetStatus" == "UP" ]; then GW="$(GetGW)" IP="$(GetIP)" PublicIP="$(GetPublicIP)" # Msg+="$InetDev successfully started and is a gateway\n\n" Msg+="Internet is $InternetStatus\n" Msg+="IP=$IP\n" Msg+="gw=$GW\n" Msg+="Public IP=$PublicIP\n" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=250 else Msg="Internet ($InetDev) is down" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=200 fi}
Without looking at what your functions are actually doing:-
Things that I don't understand:
- 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.
- 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.
- 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.
- 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
"grep search | awk {...}" is the same as "awk '/search/ {...}"
"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!
-T
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 }
UpDownedEthernetDevices eth1=$(netstat -rn | grep UG | awk '{print $8}' | sed -n 1,1p)
if [ -z $eth1 ]; then eth1=eno2 echo "Unable to find an Internet connected device, defaulting to $eth1" fi
This is the updated functions I originally posted. They contain fixes you pointed out and tabs in the status function to pretty it up:
InetDev=eno2
function GetIP () { echo "$(ip -f inet route | grep -i $InetDev | grep -i src | awk '{print $9}')" }
function CheckInternetStatus () { local GoogleDNS="8.8.8.8"; local RtnStr="$( ping -W .1 -c 1 $GoogleDNS | grep loss );" # echo "RtnStatus = <$?> RtnStr = <$RtnStr>" > "/dev/tty" if [[ "$RtnStr" == *", 0% packet loss"* ]]; then echo "UP" else echo "DOWN" fi }
function GetPublicIP () { local WIP=$(dig +short myip.opendns.com @resolver1.opendns.com) # echo "WIP = <$WIP>" > "/dev/tty" if [[ "$WIP" == *"not found"* || "$WIP" == *"no servers could be reached"* ]]; then WIP="Not Found" fi
echo $WIP }
function GetGW () { echo "$(route -n | grep $InetDev | grep UG | sed -n 1,1p | awk '{print $2}')" }
function UpDownedEthernetDevices () { local State="" local LinkState=""
for Line in $(/usr/bin/nmcli device | grep ethernet | awk '{print $1}'); do State="$(/usr/bin/nmcli device | grep $Line | awk '{print $3}')" LinkState="$(ip address | grep $InetDev | 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 }
function DisplayStatus () { NotifySound
local Msg="" local GW="" local IP="" local InternetStatus="$(CheckInternetStatus)" local PublicIP=""
# if [ -n "$(netstat -rn | grep -i $InetDev | grep -i UG)" ]; then if [ "$InternetStatus" == "UP" ]; then GW="$(GetGW)" IP="$(GetIP)" PublicIP="$(GetPublicIP)"
# Msg+="$InetDev successfully started and is a gateway\n\n" Msg+="\tInternet is $InternetStatus\n\n" Msg+="IP\t\t= $IP\n" Msg+="gw\t\t= $GW\n" Msg+="Public IP\t= $PublicIP\n"
echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=250
else Msg="Internet ($InetDev) is down" echo -e $Msg > "/dev/tty" zenity --title "$Title Status" --info --text "$Msg" --width=200 fi }
On 2020-08-22 15:07, ToddAndMargo via users wrote:
I use absolute paths when I will sometimes be operating outside the shell.
Okay, before someone tells me that bash programs ALWAYS run inside the shell and I do not path many of the other comands, it is because I program in Raku a lot. I ADORE Raku. (The documentation stinks though.) And I use nmcli a lot inside Raku.
And I prefer run system command OUTSIDE the shell, especially since my programs often run outside the shell as well. Since I trouble shoot them from a shell, it gets weird trying to figure out what you did wrong when you run them outside them shell.
One thing you have to wrap your head around when call things outside the shell it that the quotes you use inside the shell are interpreted by the shell.
So command "1" "2 3 4"
would be $1 = 1 $2 = 2 3 4
But run outside the shell would be $1 = "1" $2 = " $3 = 3 $4 = 4"
Once you get the hang of it, it is kind of fun.
On 2020-08-23 06:07, ToddAndMargo via users wrote:
Missed that. Now they are all absolute paths. Good catch. Thank you!
I use absolute paths when I will sometimes be operating outside the shell. It is a habit of mine to not trust $PATH from the shell. I do it all the time as a "just in case".
So, does that mean you need to make *all* commands full path names?
i.e. zenity, echo, netstat, grep, awk, etc.
On Sun, Aug 23, 2020 at 12:07 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-22 05:25, Tom H wrote:
- Why do you use "/usr/bin/nmcli" 6 times and "nmcli" twice?
There's no need for absolute paths.
Missed that. Now they are all absolute paths. Good catch. Thank you!
I use absolute paths when I will sometimes be operating outside the shell. It is a habit of mine to not trust $PATH from the shell. I do it all the time as a "just in case".
Did you turn all the other commands into absolute paths? (I hope not.)
If you're worried about not finding a command, set "PATH=..." after the shebang.
On Sat, 2020-08-22 at 15:07 -0700, ToddAndMargo via users wrote:
I use absolute paths when I will sometimes be operating outside the shell.
Wouldn't it be easier to set up the path in your script, rather than use full paths for every command?
On 2020-08-23 00:42, Ed Greshko wrote:
On 2020-08-23 06:07, ToddAndMargo via users wrote:
Missed that. Now they are all absolute paths. Good catch. Thank you!
I use absolute paths when I will sometimes be operating outside the shell. It is a habit of mine to not trust $PATH from the shell. I do it all the time as a "just in case".
So, does that mean you need to make *all* commands full path names?
i.e. zenity, echo, netstat, grep, awk, etc.
Only the ones I think I will copy and paste into a Raku program.
Or ones found in /usr/sbin, which is not always in the path.
On 2020-08-23 02:54, Tim via users wrote:
On Sat, 2020-08-22 at 15:07 -0700, ToddAndMargo via users wrote:
I use absolute paths when I will sometimes be operating outside the shell.
Wouldn't it be easier to set up the path in your script, rather than use full paths for every command?
Only the ones I think I will copy and paste into Raku and those found in /usr/sbin, which is not always in the path
On 2020-08-23 02:19, Tom H wrote:
On Sun, Aug 23, 2020 at 12:07 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-22 05:25, Tom H wrote:
- Why do you use "/usr/bin/nmcli" 6 times and "nmcli" twice?
There's no need for absolute paths.
Missed that. Now they are all absolute paths. Good catch. Thank you!
I use absolute paths when I will sometimes be operating outside the shell. It is a habit of mine to not trust $PATH from the shell. I do it all the time as a "just in case".
Did you turn all the other commands into absolute paths? (I hope not.)
If you're worried about not finding a command, set "PATH=..." after the shebang.
I could use that with /usr/sbin. Sweet. Thank you!
Exact path helps where things have the same names too:
/etc/alternatives/ifup /usr/sbin/ifup /usr/share/bash-completion/completions/ifup /var/lib/alternatives/ifup
On 2020-08-23 02:53, Patrick O'Callaghan wrote:
On Sat, 2020-08-22 at 18:21 -0700, ToddAndMargo via users wrote:
- 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.
head -1
poc
Interesting. It will print the first lines or the last lines. Thank you!
Sed allows me to pick which ones I want.
On 2020-08-23 16:01, ToddAndMargo via users wrote:
On 2020-08-23 02:53, Patrick O'Callaghan wrote:
On Sat, 2020-08-22 at 18:21 -0700, ToddAndMargo via users wrote:
- 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.
head -1
poc
Interesting. It will print the first lines or the last lines. Thank you!
Sed allows me to pick which ones I want.
It is the method `lines` in Raku.
On 8/23/20 3:52 PM, ToddAndMargo via users wrote:
Exact path helps where things have the same names too:
/etc/alternatives/ifup /usr/sbin/ifup /usr/share/bash-completion/completions/ifup /var/lib/alternatives/ifup
How is that relevant? Only one of those should ever be in the path and of the two that are executable (symbolic links to an executable), only one should be executed.
On 2020-08-23 18:22, Samuel Sieb wrote:
On 8/23/20 3:52 PM, ToddAndMargo via users wrote:
Exact path helps where things have the same names too:
/etc/alternatives/ifup /usr/sbin/ifup /usr/share/bash-completion/completions/ifup /var/lib/alternatives/ifup
How is that relevant? Only one of those should ever be in the path and of the two that are executable (symbolic links to an executable), only one should be executed.
It may or may not be relevant. It was just the easiest example I could find
On Sun, 2020-08-23 at 16:01 -0700, ToddAndMargo via users wrote:
On 2020-08-23 02:53, Patrick O'Callaghan wrote:
On Sat, 2020-08-22 at 18:21 -0700, ToddAndMargo via users wrote:
- 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.
head -1
poc
Interesting. It will print the first lines or the last lines. Thank you!
Sed allows me to pick which ones I want.
'head' prints the first N lines (10 by default). See also 'tail'.
You said you wanted the first line, so 'head' is the obvious command, but as with most things in UNIX/Linux, there is more than one way of doing it.
poc
On Sun, Aug 23, 2020 at 3:23 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-22 02:53, Tom H wrote:
- 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.
:)
- 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.
- 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?
- 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
"grep search | awk {...}" is the same as "awk '/search/ {...}"
"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 fidone }
You're using eno2 rather than a variable.
Why do you need "beesu" for "ip" and not for "nmcli"?
On 2020-08-24 02:21, Patrick O'Callaghan wrote:
On Sun, 2020-08-23 at 16:01 -0700, ToddAndMargo via users wrote:
On 2020-08-23 02:53, Patrick O'Callaghan wrote:
On Sat, 2020-08-22 at 18:21 -0700, ToddAndMargo via users wrote:
- 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.
head -1
poc
Interesting. It will print the first lines or the last lines. Thank you!
Sed allows me to pick which ones I want.
'head' prints the first N lines (10 by default). See also 'tail'.
You said you wanted the first line, so 'head' is the obvious command, but as with most things in UNIX/Linux, there is more than one way of doing it.
poc
With sed I can pick out what line or lines I want. Makes it universal. Once I learn how to do something I tend to stick with it.
With Linux, here is always 11 ways of doing everything. With Raku (Perl 6) there is always 101 ways of doing everything.
Makes both Linux and Raku fun to work with. I do program somewhat in Windows, but it is no where near as much fun.
On Sun, Aug 23, 2020 at 3:30 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-22 15:07, ToddAndMargo via users wrote:
I use absolute paths when I will sometimes be operating outside the shell.
Okay, before someone tells me that bash programs ALWAYS run inside the shell and I do not path many of the other comands, it is because I program in Raku a lot. I ADORE Raku. (The documentation stinks though.) And I use nmcli a lot inside Raku.
And I prefer run system command OUTSIDE the shell, especially since my programs often run outside the shell as well.
I guess that what you call "outside the shell" means non-interactively.
In Perl 5, you can set the PATH just like in a shell script with '[local] $ENV{PATH} = "...";'. Didn't Raku keep this or replace it with something of similar purpose?
On 2020-08-24 04:04, Tom H wrote:
On Sun, Aug 23, 2020 at 3:23 AM ToddAndMargo via users
In the unlikely event that you have two UGs on eno2, you must want both, no?
I do not remember what circumstances I saw it, but it goof me up, so I left the fist line filter in place.
True. I only what the first instance.
echo "Reattaching (link) $Line" > "/dev/tty" beesu "ip link set $Line down; ip link set $Line up;"
You're using eno2 rather than a variable.
That has been fixed.
Why do you need "beesu" for "ip" and not for "nmcli"?
I have not found a way with nmcli to up the "link". "connect" and "device" don't seems to touch it.
$ ip link set eno2 down; ip link set eno2 up; RTNETLINK answers: Operation not permitted RTNETLINK answers: Operation not permitted
On 2020-08-24 04:19, Tom H wrote:
On Sun, Aug 23, 2020 at 3:30 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-22 15:07, ToddAndMargo via users wrote:
I use absolute paths when I will sometimes be operating outside the shell.
Okay, before someone tells me that bash programs ALWAYS run inside the shell and I do not path many of the other comands, it is because I program in Raku a lot. I ADORE Raku. (The documentation stinks though.) And I use nmcli a lot inside Raku.
And I prefer run system command OUTSIDE the shell, especially since my programs often run outside the shell as well.
I guess that what you call "outside the shell" means non-interactively.
In Perl 5, you can set the PATH just like in a shell script with '[local] $ENV{PATH} = "...";'. Didn't Raku keep this or replace it with something of similar purpose?
I have forgotten most of what I learned in Perl 5. When Perl 6 hit, I jumped on it. I program in Top Down and live and both modules and subroutines. Perl's 5 method of calling subs is a freaking nightmare. Raku's sub declarations are a dream.
By "outside the shell", I mean that bash and friends are not involved. $PATH is part of bash's shell. The programs themselves are call directly.
In Raku, it looks like this:
$proc = run( @RunArray, :err, :out, :bin );
You place each parameter in a separate cell. This gets around the "space" in the parameter issue
On Mon, Aug 24, 2020 at 12:53 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-23 02:19, Tom H wrote:
If you're worried about not finding a command, set "PATH=..." after the shebang.
I could use that with /usr/sbin. Sweet. Thank you!
You're welcome.
Exact path helps where things have the same names too:
/etc/alternatives/ifup /usr/sbin/ifup /usr/share/bash-completion/completions/ifup /var/lib/alternatives/ifup
?!
You only need "/usr/sbin" in PATH to use "ifup".
You definitely don't need any "completions" in a script.
The way that alternatives work is that imagine if Fedora offered ksh93, mksh, and oksh as different versions of ksh and that they were set up via the alternatives mechanism.
There'd be "/bin/{ksh,ksh93,mksh,oksh}" with "/bin/ksh" being a symlink to "/etc/alternatives/ksh" and "/etc/alternatives/ksh" being a symlink to whichever ksh version you wanted to use as ksh.
On 2020-08-24 04:43, Tom H wrote:
On Mon, Aug 24, 2020 at 12:53 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-23 02:19, Tom H wrote:
If you're worried about not finding a command, set "PATH=..." after the shebang.
I could use that with /usr/sbin. Sweet. Thank you!
You're welcome.
Exact path helps where things have the same names too:
/etc/alternatives/ifup /usr/sbin/ifup /usr/share/bash-completion/completions/ifup /var/lib/alternatives/ifup
?!
You only need "/usr/sbin" in PATH to use "ifup".
If memory serves me, "/usr/sbin" is in bash's default path for root only. I usually put it into my users' path anyway.
You definitely don't need any "completions" in a script.
Not following what you mean by "completions"
The way that alternatives work is that imagine if Fedora offered ksh93, mksh, and oksh as different versions of ksh and that they were set up via the alternatives mechanism.
There'd be "/bin/{ksh,ksh93,mksh,oksh}" with "/bin/ksh" being a symlink to "/etc/alternatives/ksh" and "/etc/alternatives/ksh" being a symlink to whichever ksh version you wanted to use as ksh.
True. I started with c shell (csh or something like that) in Sun OS.
Keep in mind that I call things outside any shell. If I know there is a possibility with a bash program that I will copy and paste to a Raku program, I usually will include the full path. It is just a help for me.
On Mon, Aug 24, 2020 at 1:22 PM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-24 04:04, Tom H wrote:
Why do you need "beesu" for "ip" and not for "nmcli"?
I have not found a way with nmcli to up the "link". "connect" and "device" don't seems to touch it.
$ ip link set eno2 down; ip link set eno2 up; RTNETLINK answers: Operation not permitted RTNETLINK answers: Operation not permitted
Sorry. I was being stupid. nmcli can be used by admins without su or something similar.
On 8/24/20 5:01 AM, ToddAndMargo via users wrote:
On 2020-08-24 04:43, Tom H wrote:
On Mon, Aug 24, 2020 at 12:53 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
/usr/share/bash-completion/completions/ifup
You definitely don't need any "completions" in a script.
Not following what you mean by "completions"
When you press the TAB key in bash, it can run various scripts to try to complete what you're currently typing. Those are called completions and are generally stored in that directory. That "ifup" file contains the scripts for handling options for the ifup command. e.g. If you type "ifup" and press TAB twice, it will show you all the available connections you have that you could be bringing up.
On 2020-08-24 12:56, Samuel Sieb wrote:
On 8/24/20 5:01 AM, ToddAndMargo via users wrote:
On 2020-08-24 04:43, Tom H wrote:
On Mon, Aug 24, 2020 at 12:53 AM ToddAndMargo via users users@lists.fedoraproject.org wrote:
/usr/share/bash-completion/completions/ifup
You definitely don't need any "completions" in a script.
Not following what you mean by "completions"
When you press the TAB key in bash, it can run various scripts to try to complete what you're currently typing. Those are called completions and are generally stored in that directory. That "ifup" file contains the scripts for handling options for the ifup command. e.g. If you type "ifup" and press TAB twice, it will show you all the available connections you have that you could be bringing up.
Hi Sam,
$ ifup \t\t br0 eno1 eno2
$ ls /home/CDs/Win \t\t Windows/ WindowsInternet/ WinPE/
I use a single tab all the time but have never used it twice. Awesome! Thank you!
Linux: now 102 ways of doing things!
:-)
-T
On 2020-08-24 12:06, Tom H wrote:
On Mon, Aug 24, 2020 at 1:22 PM ToddAndMargo via users users@lists.fedoraproject.org wrote:
On 2020-08-24 04:04, Tom H wrote:
Why do you need "beesu" for "ip" and not for "nmcli"?
I have not found a way with nmcli to up the "link". "connect" and "device" don't seems to touch it.
$ ip link set eno2 down; ip link set eno2 up; RTNETLINK answers: Operation not permitted RTNETLINK answers: Operation not permitted
Sorry. I was being stupid. nmcli can be used by admins without su or something similar.
I was hoping I was wrong as it would have made the code a little easier to run.
I am wrong a lot. Now was not the time to be right about something!
:'(
On 2020-08-24 02:21, Patrick O'Callaghan wrote:
On Sun, 2020-08-23 at 16:01 -0700, ToddAndMargo via users wrote:
On 2020-08-23 02:53, Patrick O'Callaghan wrote:
On Sat, 2020-08-22 at 18:21 -0700, ToddAndMargo via users wrote:
- 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.
head -1
poc
Interesting. It will print the first lines or the last lines. Thank you!
Sed allows me to pick which ones I want.
'head' prints the first N lines (10 by default). See also 'tail'.
You said you wanted the first line, so 'head' is the obvious command, but as with most things in UNIX/Linux, there is more than one way of doing it.
poc
Some Raku trivia. Print lines 3, 2, 5 in that order
$ cat Lines.txt Line 0 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11
$ cat Lines.txt | raku -e ' my @x=$*IN.lines; for @x[3,2,5] {say $_};' Line 3 Line 2 Line 5
On 2020-08-24 20:07, ToddAndMargo via users wrote:
On 2020-08-24 02:21, Patrick O'Callaghan wrote:
On Sun, 2020-08-23 at 16:01 -0700, ToddAndMargo via users wrote:
On 2020-08-23 02:53, Patrick O'Callaghan wrote:
On Sat, 2020-08-22 at 18:21 -0700, ToddAndMargo via users wrote:
- 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.
head -1
poc
Interesting. It will print the first lines or the last lines. Thank you!
Sed allows me to pick which ones I want.
'head' prints the first N lines (10 by default). See also 'tail'.
You said you wanted the first line, so 'head' is the obvious command, but as with most things in UNIX/Linux, there is more than one way of doing it.
poc
Some Raku trivia. Print lines 3, 2, 5 in that order
$ cat Lines.txt Line 0 Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11
$ cat Lines.txt | raku -e ' my @x=$*IN.lines; for @x[3,2,5] {say $_};' Line 3 Line 2 Line 5
And even quicker!
$ cat Lines.txt | raku -e '.say for lines()[3,2,5]' Line 3 Line 2 Line 5