由于公司安全策略要求,需要绑定了MAC地址的机器才能联网,每次新增主机都要手动绑定IP和MAC地址,
非常麻烦,所以自动绑定脚本应运而生,这是根据我们公司编写的shell脚本,大婶们见笑了,请多多指教
#!/bin/bash
list=(`sed -rn '/\(([0-9|a-z|A-Z]+:){5}[0-9|a-z|A-Z]+\)/p' tail2000.log | \
awk '{print $8" "$9}'|sed -e 's/[(|)]/ /g'|sort -rn|uniq`)
count=${#list[@]}
path=/home/dhcpd.conf
string_133="range 10.34.133.44 10.34.133.44;"
string_134="range 10.34.134.21 10.34.135.240;"
string_135="range 10.34.135.21 10.34.135.240;"
string_129="range 10.34.129.21 10.34.135.240;"
i=0
while [ $i -lt $count ]
do
num=`echo ${list[$i]:6:3}`
grep -Ewq "${list[$i]}|${list[$i+1]}" $path
if [ $? -ne 0 ];then
case $num in
129)
NO=`date +%N`
hosts=`echo "host CN${NO:1:5}{hardware ethernet ${list[$i]}; fixed-address ${list[$i+1]};}"`
sed -i "/$string_129/a '\t'$hosts" $path
sed -ir "s/'.'/\t/g" $path;;
133)
NO=`date +%N`
hosts=`echo "host CN${NO:1:5}{hardware ethernet ${list[$i]}; fixed-address ${list[$i+1]};}"`
sed -i "/$string_133/a '\t'$hosts" $path
sed -ir "s/'.'/\t/g" $path;;
134)
NO=`date +%N`
hosts=`echo "host CN${NO:1:5}{hardware ethernet ${list[$i]}; fixed-address ${list[$i+1]};}"`
sed -i "/$string_134/a '\t'$hosts" $path
sed -ir "s/'.'/\t/g" $path;;
135)
NO=`date +%N`
hosts=`echo "host CN${NO:1:5}{hardware ethernet ${list[$i]}; fixed-address ${list[$i+1]};}"`
sed -i "/$string_135/a '\t'$hosts" $path
sed -ir "s/'.'/\t/g" $path;;
esac
else
echo ${list[$i+1]} is exist!
fi
i=$(($i+2))
done
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/1398.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~