Å×½ºÆ® ȯ°æ # cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@localhost ~]# cat dhcp_monitor.sh
#!/bin/bash
rm /tmp/showdhcp.log &
rm /tmp/tmp* &
tempFile=$(mktemp)
cat /var/lib/dhcpd/dhcpd.leases \
| grep \
-e '^lease ' \
-e '^ binding state' \
-e hardware \
-e client-hostname \
-e } >$tempFile.1
sed -e "s/^lease \(.*\) {$/\1~/" \
-e "s/^ binding state \(.*\);$/\1~/" \
-e "s/^ hardware ethernet \(.*\);$/\1~/" \
-e "s/ client-hostname \(.*\);$/\1~/" \
-e "s/^}//" \
$tempFile.1 > $tempFile.2
sed -e ":'loop';/~$/N;s/~\n/,/;t'loop'" \
-e "s/,$//" \
-e "s/,/\t/g" \
$tempFile.2 | sort > $tempFile.3
sed -e'$!N;/^\(.*\)\n\1$/!P;D' $tempFile.3 > $tempFile.4
print=$(printf "IP Addr\t\tStatus\t\tMAC\t\tHost Name\n")
cat $tempFile.4 > /tmp/showdhcp.log &
sed -i "1i $print" /tmp/showdhcp.log
#rm -rvf /tmp/Non_Active_User*
#rm -rvf /tmp/Active_User*
#cp -rvf $tempFile.4 /tmp/showdhcp.log &
free=$(grep -o -w 'free' /tmp/showdhcp.log | wc -w)
active=$(grep -o -w 'active' /tmp/showdhcp.log | wc -w)
echo -e ""
echo -e "--------- Total Count- Active & Non Active -----------"
echo -e ""
echo -e "Total Active User :" $free
echo -e "Total Non Active User :" $active
echo -e "------------------------------------------------------"
#sed -n '/free/p' /tmp/showdhcp.log > /tmp/Non_Active_User_$(date +"%Y-%m-%d__%H%M%S").log
#sed -n '/active/p' /tmp/showdhcp.log > /tmp/Active_User_$(date +"%Y-%m-%d__%H%M%S").log
rm $tempFile.*
#rm -rvf /tmp/showdhcp.log
#rm -rvf /tmp/tmp* &
[root@localhost ~]# sh dhcp_monitor.sh
--------- Total Count- Active & Non Active -----------
Total Active User : 35
Total Non Active User : 11
------------------------------------------------------
[root@localhost ~]# cat /tmp/showdhcp.log
Ãâó
http://www.ostechnix.com/monitor-dhcp-server-usage/