Script Check WiFi Users Connected
# By: Vannak Ken
# This script going to check on the connected user on wifi in the wifi listed.
TIMESTAMP=`date +%Y-%m-%d-%H:%M:%S`
MAILTO="ken.vannakk@gmail.com vannak.ken@example.com"
for i in `cat /opt/scripts/wifi/all-wifi.txt`;
do
# ------------------------------- NUMBER USERS CONNECTED ------------------------------------------ #
USERCONNECTED=`snmpwalk $i -v 1 -c PuBlic_SNMP-RO enterprises.41112.1.4.5.1.15.1 |awk '{print $4}'`
echo "$i : $USERCONNECTED" >> /opt/scripts/wifi/wifi-report-$TIMESTAMP.txt
#USERS CONNECT MORE THE 20 SEND EMAIL
USERMAX=20
if [[ "$USERCONNECTED" -ge "$USERMAX" ]];
then
echo "$i Users More Than 20." > /opt/scripts/wifi/wifi-20users-or-more.txt
mail -s "$i Users More Than 20" $MAILTO < /opt/scripts/wifi/wifi-20users-or-more.txt
else
echo "$i Users Less Than 20"
fi
# ------------------------------------------------------------------------------------------------- #
# -------------------------------- CHECK WIFI NO USER OR CAN NOT CONNECTED ------------------------ #
NOUSER=0
if [[ "$USERCONNECTED" == "$NOUSER" ]]; then
echo "$i No Users connected." > /opt/scripts/wifi/wifi-no-users-connected.txt
mail -s "$i No Users connected." $MAILTO < /opt/scripts/wifi/wifi-no-users-connected.txt
else
if [[ -z "$USERCONNECTED" ]] ; then
echo "$i Cannot Connected." > /opt/scripts/wifi/wifi-cannot-connected.txt
mail -s "$i Cannot Connected" $MAILTO < /opt/scripts/wifi/wifi-cannot-connected.txt
else
echo "$i Connected normally."
fi
fi
# ------------------------------------------------------------------------------------------------- #
done
# Send email with ttached the report
mail -s "Wifi Report - $TIMESTAMP" $MAILTO < /opt/scripts/wifi/wifi-report-$TIMESTAMP.txt
rm -rf /opt/scripts/wifi/wifi-20users-or-more.txt
rm -rf /opt/scripts/wifi/wifi-no-users-connected.txt
rm -rf /opt/scripts/wifi/wifi-cannot-connected.txt
# Remove old report
find /opt/scripts/wifi/ -name "*.txt" -mtime +30 -exec rm -f {} \;
No comments:
Post a Comment