Reputation: 130
I want to to check every 3 second if the difference of the numbers is higher than 1000. How can I get the old value, for example: 16598, every time?
while true; do
testbro=$(wc -l < /home/web/log/access.log)
echo $testbro
sleep 3
done
It outputs as wanted:
16414
16471
16533
16598
16666
Upvotes: 1
Views: 51
Reputation: 42999
If your intention is to detect when your file grows >= 1000 lines in a 3 second period, you could do this:
#!/bin/bash
last_size=$(wc -l < /home/web/log/access.log)
while true; do
sleep 3
curr_size=$(wc -l < /home/web/log/access.log)
if ((curr_size - last_size >= 1000)); then
echo "$curr_size"
fi
last_size=$curr_size
done
Upvotes: 2