Re: Script help

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

 



On Feb 12, 2008 5:23 AM, Tom Brown <tom@xxxxxxxx> wrote:
> Hi
>
> I am scripting some post install bits on a kickstart machine that
> downloads certain configuration files depending on the network the
> machine is in.
>
> I am trying to construct an if statement that will run something like
>
>
>
> ADDR=`ifconfig | grep "inet addr" | head -2 | awk '{print$2'} | cut -c
> 14,15`
>
> if [ "$ADDR" = "11" ] ; then
>         echo "downloading bar"
> fi
>
> if [ "$ADDR" = "12" ] ; then
>         echo "downloading foo"
>
> fi
>
> etc
>
> and there are 5 different configs - If none of the configs are found
> then it downloads a default - Am i going about this the right way?
>
> thanks

As Todd suggested, the case command will work well for this scenario.
Are you sure your ADDR= command is going to work as expected for
various scenarios?  I'm not sure of the reason for head -2, and the
cut command might not yield the desired results either depending on
the number of digits in the octets of your IPs.  Is there more than
one NIC in the machines? Also you are catching your loopback address
with the current scenario.  You could add a grep -v 127.0.0.1 to
eliminate the loopback.  Also instead of awk you can do the following
using sed and then pattern substitution.

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.

-- 
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