Advertisement
Guest User

pcibus-to-name

a guest
Mar 23rd, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/bash
  2. # Used to map PCI bus to name
  3.  
  4. # CONSTANTS
  5. INTF_NAME="eth"
  6. INTF_NUMBER=0
  7. RULES_FILE="/etc/udev/rules.d/70-persistent-net.rules"
  8.  
  9. # Get all PCI bus, order them ascending and assign to an array
  10. pci_bus_array=( $(for dir in /sys/class/net/* ; do [ -e $dir/device ] && { basename $dir ; readlink -f $dir/device; }; done | grep devices | sort -n) )
  11.  
  12. # Iterate through PCI bus array and change each NIC name
  13. for pci_bus in "${pci_bus_array[@]}"; do
  14.  
  15.   echo "Mapping ${pci_bus} to $INTF_NAME$INTF_NUMBER"
  16.   line_number=$(grep -n $pci_bus $RULES_FILE | awk -F: '{print $1}')
  17.   line_number=$(($line_number + 1))
  18.   sed -i "${line_number}s/eth[0-9]/${INTF_NAME}${INTF_NUMBER}/" $RULES_FILE
  19.   INTF_NUMBER=$(($INTF_NUMBER + 1))
  20.  
  21. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement