In my script I need to randomly generate MAC addresses. The code below is from a larger script extracted, that's why the MAC address calculation is in a separate function.
This works fine with the code below. Although when I execute the script it slows heavily down after a number of generated addresses.
How can I improve the speed of generating valid MAC addresses?
#!/bin/bash
devicesCSVMacAddress="55:2d:fa:07" # <- fake MAC address prefix
devicesCSVFile=''
function mac_address() {
line=''
# ****************
# This line below when I calculate a random mac address ending seems to be slow
line+=$devicesCSVMacAddress$(od -txC -An -N2 /dev/random|tr \ :)
# ****************
devicesCSVFile+=$line'\n'
date
}
for (( i=0; i<100; i++ ))
do
mac_address
echo $i
done
echo -e $devicesCSVFile > devices.csv
I used the od tool like it described in this answer: How to generate a valid random MAC Address with bash shell.