SVN 3080: NIC Registration
-
I wonder
[code]for macline in $(ip addr show | grep link/ether|awk ‘{print $2}’); do
# Add a pipe before adding more MACs
if [ -n “$mac” ]; then
mac=$mac|
fi
done[/code]This, from what I can tell, should allow us to just echo back the mac variable and we don’t need the xargs and cut commands to operate as the only things returned is our pipe delimited list of MAC Addresses.
-
[code]# Get All Active MAC Addresses
getMACAddresses()
{
IFS=$‘\n’
# Create a pipe-separated MAC List
for macline in $(ip addr | grep link/ether | awk ‘{print $2}’); do
# Add a pipe before adding more MACs
if [ -n “$mac” ]; then
mac=$mac|
fi
mac=$macecho $macline
;
done
IFS=
echo $mac
}[/code] -
[quote=“Tom Elliott, post: 43618, member: 7271”]Oh, i do have a thought though.
Using the generate our interfaces file on the fly method, I can add the e-polling capabilities of the kernel to use more proper methods of device management. This means not all devices will automatically have eth* names, but rather whatever the device is. Is there a simpler way without designating the specific devices to search for?[/quote]
[CODE]# Set for loop delimiters to just newline
IFS=$‘\n’Create a pipe-separated MAC list
for macline in $(ip addr | grep link/ether)
do
# Add a pipe before adding more MACs
if [ -n “$mac” ]; then
mac=$mac|
fi
mac=$macecho $macline | xargs | cut -d ' ' -f 2
doneReset delimiters
IFS=[/CODE]
I just realized I was doing a grep on link/ether so that doesn’t include lo. Enjoy!
-
Not using any extra ip tools … /sys/class/net/*/address …
-
[code]# Get All Active MAC Addresses
getMACAddresses()
{
IFS=$‘\n’
# Create a pipe-separated MAC List
for macline in $(ip addr | grep link/ether | awk ‘{print $2}’); do
# Add a pipe before adding more MACs
if [ -n “$mac” ]; then
mac=$mac|
fi
mac=${mac}${macline};
done
IFS=
echo $mac
}[/code]Caught a bug with your final mac= statement. Also, “ip addr” is fine by itself.
-
yeah I saw and edited. The echo needs to occur there. and I am using just ip addr
-
[quote=“Uncle Frank, post: 43623, member: 28116”]Not using any extra ip tools … /sys/class/net/*/address …[/quote]
We have to know the exact path name, so it’s simpler to just use the tools that get that for us I think.
-
[quote=“Tom Elliott, post: 43626, member: 7271”]We have to know the exact path name, so it’s simpler to just use the tools that get that for us I think.[/quote]
I don’t think so…
[CODE]# Get All Active MAC Addresses
getMACAddresses()
{
IFS=$‘\n’
# Create a pipe-separated MAC List
for macline in $(cat /sys/class/net/*/address); do
# Add a pipe before adding more MACs
if [ -n “$mac” ]; then
mac=$mac|
fi
mac=${mac}${macline};
done
IFS=
echo $mac
}[/CODE]
No ip, no awk, no grep… -
And I still wonder, why do we need the IFS here??
-
[quote=“Uncle Frank, post: 43627, member: 28116”]I don’t think so…
[CODE]# Get All Active MAC Addresses
getMACAddresses()
{
IFS=$‘\n’
# Create a pipe-separated MAC List
for macline in $(cat /sys/class/net/*/address); do
# Add a pipe before adding more MACs
if [ -n “$mac” ]; then
mac=$mac|
fi
mac=${mac}${macline};
done
IFS=
echo $mac
}[/CODE]
No ip, no awk, no grep…[/quote]It grabs lo’s MAC. But I like where this is going…
-
[CODE]… cat /sys/class/net/???*/address …[/CODE] kind of hackish but…
-
How low can we go?
[CODE]# Get All Active MAC Addresses
getMACAddresses()
{
lomac=00:00:00:00:00:00
cat /sys/class/net/*/address | grep -v $lomac | tr ‘\n’ ‘|’ | sed s/.$//g
}[/CODE] -
sed, grep, tr and all the rest are very nice but we don’t really need them here, do we?
[CODE]… cat /sys/class/net/[^l][^o]*/address …[/CODE]And still wondering about if ‘IFS’ is needed here. Sorry goto go now.
-
I like it
-
Uncle Frank, cspence’s means no loops either!
-
[quote=“Tom Elliott, post: 43634, member: 7271”]Uncle Frank, cspence’s means no loops either![/quote]
Moments like these are why I love collaborating with others on code. Just a few suggestions and the code collapses to nothing.
-
[quote=“Uncle Frank, post: 43632, member: 28116”]
[CODE]… cat /sys/class/net/[^l][^o]*/address …[/CODE]
[/quote]What does that even mean?
I know DOS and VB, some Oracle… That stuff is so foreign I feel like it’s terrorist related lol -
lol
it means to cat all directories EXCEPT those with l, then o (or in this case lo) -
[quote=“Tom Elliott, post: 43634, member: 7271”]Uncle Frank, cspence’s means no loops either![/quote]
Ohhhhh yes, now I see! Shouldn’t work till very late as I seem to overlook things too often then…I’d vote for bash string manipulation…
[CODE]# Get All Active MAC Addresses
getMACAddresses()
{
macs=$(cat /sys/class/net/[^l][^o]*/address | tr ‘\n’ ‘|’)
echo -n ${macs%$‘|’}
}[/CODE]
Just make sure we use BASH (not SH) because the terrorist style (lol) shell glob does not work with SH… -
[quote=“Uncle Frank, post: 43632, member: 28116”]sed, grep, tr and all the rest are very nice but we don’t really need them here, do we?
[CODE]… cat /sys/class/net/[^l][^o]*/address …[/CODE]And still wondering about if ‘IFS’ is needed here. Sorry goto go now.[/quote]
Very usefull, I’ll use in my script !