话不多说,直接上脚本
#!/bin/bash
while :
do
time=$(date "+%Y-%m-%d-%H:%M:%S")
logfile=./log_size_monitor.log
srs_log=/usr/local/srs/objs/srs.log
echo $time >> $logfile
size_srs=$[$(ls -l $srs_log | awk {'print $5'})/1048576]
size_monitor=$[$(ls -l $logfile | awk {'print $5'})/1048576]
echo "the size of srs.log is $size_srs M" >> $logfile
echo "the size of log_size_monitor.log is $size_monitor M" >> $logfile
if [ $size_srs -gt 20 ];then
cp $srs_log $srs_log.$time
> $srs_log
fi
if [ $size_monitor -gt 20 ];then
cp $logfile $logfile.$time
> $logfile
fi
sleep 60
done