Re: How to detect the number of network adapters installed from kickstart file for network config?

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

 



On 02/19/2011 02:37 AM, Pat wrote:
My kickstart file is usually used on systems with 1 or 2 network interfaces installed. If my kickstart file has the following lines:

network --device eth0 --bootproto dhcp
network --device eth1 --onboot no --bootproto dhcp


It will fail if I use it on a system with only 1 network interface since eth1 doesn't exist.

From a kicksstart file how do I detect the number of network interfaces installed on the system and then only assign eth1 as above if that number is 2 or more? If it matters, it's possible the network interfaces are not plugged into the network when the kickstart is run. Thanks.

You could test for the number of interfaces. Since I'm a total n00b in this area hopefully the experienced folks who monitor this list will have a good laugh at my "scripting" and come up with something better that actually works :)

Here's how I would try to solve it. Totally untested, use at own risk. Mind the linewrap. It's all one line. My box has lo, br0, eth0 and virbr0 so the script should give a total of 4 interfaces.

$ ifconfig -a | grep -vE 'inet|UP|RX|TX|collisions|Interrupt' | awk 'BEGIN {no_of_interfaces=0} /^[a-z]/ {print $1}' | awk 'END {no_of_interfaces=NR; print "Number of interfaces: " no_of_interfaces}'

Number of interfaces: 4 (correct so apparently this works)

You could add this to the %pre section in your kickstart file:

%pre
NO_OF_INTERFACES=`ifconfig -a | grep -vE 'inet|UP|RX|TX|collisions|Interrupt' | awk 'BEGIN {no_of_interfaces=0} /^[a-z]/ {print $1}' | awk 'END {no_of_interfaces=NR; print no_of_interfaces}'`
echo "INTERFACE_COUNT=$NO_OF_INTERFACES" > /tmp/interface_count.txt

Then in the %post section test if the value is greater than or equal to 2 in which case you configure both interfaces. Or else configure one interface:

%post
# first get the nr of interfaces from the interface_count.txt file
# afaik usually at the top of %post
source /tmp/interface_count.txt

# test the value. not sure if I need to quote INTERFACES and 2
if [ "\$INTERFACE_COUNT" -ge "2" ]; then
  # configure 2 nics
  network --device eth0 --bootproto dhcp
  network --device eth1 --onboot no --bootproto dhcp
else
  # configure 1 nic
  network --device eth0 --bootproto dhcp
fi

Since I don't know awk I got the syntax from the excellent n00b-friendly awk tutorial at http://bashshell.net/stream-filtering-utilities/exercise-1-learning-awk-basics/

Hope this helps.

Regards,
Patrick

_______________________________________________
Kickstart-list mailing list
Kickstart-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/kickstart-list


[Index of Archives]     [Red Hat General]     [CentOS Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux