I came across this question when I was trying to get better/logged output from du -sh $data_path
. I used the "while command, do sleep" pattern found here, but used some complex AWK to give the output I wanted.
while du -sh $data_path; do sleep 1; done | awk '
$1 != size {
size=$1;
path=$2;
time=systime();
seconds=time-prevtime;
if(seconds < 1000000000){
seconds=seconds" seconds"
}else{
seconds=""
}
print size, path, strftime("%m/%d/%Y@%H:%M:%S", time), seconds;
prevtime=time
}'
I actually did this as a oneliner, which is why there are semicolons. But to make it readable, I broke it out. The output looks like:
502G /var/lib/cassandra/dump/ 05/22/2018@04:46:17
503G /var/lib/cassandra/dump/ 05/22/2018@04:46:59 42 seconds
504G /var/lib/cassandra/dump/ 05/22/2018@04:47:57 58 seconds
505G /var/lib/cassandra/dump/ 05/22/2018@04:48:55 58 seconds
506G /var/lib/cassandra/dump/ 05/22/2018@04:49:53 58 seconds
507G /var/lib/cassandra/dump/ 05/22/2018@04:50:50 57 seconds
508G /var/lib/cassandra/dump/ 05/22/2018@04:51:46 56 seconds
509G /var/lib/cassandra/dump/ 05/22/2018@04:52:44 58 seconds
510G /var/lib/cassandra/dump/ 05/22/2018@04:53:41 57 seconds
wait
- just trywatch -n 1 "sleep 5"
. – peterph Nov 19 '12 at 12:26watch
was useful for, but it doesn't give you even that so your solution is as good as a watch based one, but neither answers the "rate at which a log file grows" question with great accuracy. – Stéphane Chazelas Nov 19 '12 at 13:22watch
has a-p
option that will do that right, if at all possible (obviously, you can't do a command that takes 5 seconds every 1 second, if you're not allowed multiple simultaneous). I know, I wrote it :-P – derobert Jun 19 '14 at 17:46watch
from procps-ng? For the "canonical" one from the procps definitely doesn't have this option. – peterph Jun 20 '14 at 07:19watch
only supports intervals down to 0.1 seconds, whilesleep
supports "floating point numbers" as intervals (e.g.sleep 0.0001
works just fine). – rinogo Oct 16 '20 at 01:20