脚本如下:
#!/bin/bash
d=`date +%d`
d1=`date +%H`
ip=192.168.0.
logdir=/tmp/log/$d.log
dir=/root/user_ip.txt
exec 2> /tmp/f.log
while :
do
for i in `seq 1 254`
do
a=`grep $ip$i | wc -l `
n=`ping -c 1 $ip$i | grep -w packets | awk -F "%" ‘{print $1}‘ |awk ‘{print $6}‘`
name=`grep $ip$i $dir | awk ‘{print $1}‘
if [ n == 0 ]
then
if [ $d1 -lt 9 -a $d1 -gt 18 ]
then
if [ ! a == 0 ]
then
if [ `grep -v $name $logdir ` ]
then
echo $name 是个努力的小伙伴 >> $logdir
fi
else
echo -n `date`
echo " please check the user`s ip $ip$i " >> /tmp/f.log
fi
fi
else
if [ $d1 -ge 9 -a $d1 -le 18 ]
then
if [ ! a == 0 ]
then
if [ `grep -v $name $logdir` ]
then
echo $name 是个小懒虫 >> $logdir
if
else
echo -n `date`
echo " please check the user`s ip $ip$i " >> /tmp/f.log
fi
fi
fi
done
sleep 60
done