Re: Script help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jacques B. wrote:
<snip>
ADDR=$(ifconfig | sed -e '/127.0.0.1/d' -n -e '/inet addr/p') # ADDR
will contain all the lines with "inet addr" except the loopback.
ADDR=${ADDR%% Bcast*} # output will contain "inet addr:192.168.0.1"
(or whatever your IP is of course)
ADDR=${ADDR##*.} # ADDR will contain the last octect in the IP, "1" in
the above scenario

case $ADDR in
    11 ) echo "downloading bar";;
    12 ) echo "downloading foo";;
    13 ) echo "downloading whatever";;
      * ) echo "Unknown network.  Did not match any of the choices.";;
esac

Note that the above works for a scenario where there is only one NIC
activated.  I haven't tested it with multiple NICs.

Jacques B.


Further to that last message, I re-ran it without the 127.0.0.1
portion of the sed command and it still worked.  Reason being is that
the result of the sed is saved to the variable as a single string (so
the inet addr for eth0 followed by the inet addr line for the
loopback).  So when you do the pattern machine on the next line, only
the very first NIC is retained.  So the script is only suitable if you
only have to worry about the first NIC.  And like I said, the sed
command could be as below and it will function the same.
sed -n -e '/inet addr/p'

If you need to deal with multiple NICs where you are interested in a
NIC other than the first one listed, you'll have to script this
differently.

Jacques B.


thanks for the pointers all - this was being tested on a box that has more than 1 NIC hence the reason for the cut.

I need to get the third octect of the NIC address and depending on what that is a different automounter file is installed and if no network is recognised then a default is downloaded. I hope that clears up what i am trying to do and i will look at the options.


--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux