bash计算上下行数据差值

时间:2022-09-17 06:23:58

for i in {1..60000}; do echo "`date +'%F %T'` `df /dev/md0 | grep 'data1'` "; sleep 1; done | awk '{a[NR]=$6; print $0,a[NR]-a[NR-1]}'

[root@TENCENT64 ~]# for i in {1..60000}; do echo "`date +'%F %T'` `df /dev/md0 | grep 'data1'` "; sleep 1; done | awk '{a[NR]=$6; print $0,a[NR]-a[NR-1]}'
2018-11-22 20:11:20 /dev/md0 6976558760 5146898460 1478037340 78% /data1 1478037340
2018-11-22 20:11:21 /dev/md0 6976558760 5146898460 1478037340 78% /data1 0
2018-11-22 20:11:22 /dev/md0 6976558760 5146918940 1478016860 78% /data1 -20480
2018-11-22 20:11:23 /dev/md0 6976558760 5146927148 1478008652 78% /data1 -8208
2018-11-22 20:11:24 /dev/md0 6976558760 5146931256 1478004544 78% /data1 -4108
2018-11-22 20:11:25 /dev/md0 6976558760 5146943560 1477992240 78% /data1 -12304
2018-11-22 20:11:26 /dev/md0 6976558760 5146947656 1477988144 78% /data1 -4096
2018-11-22 20:11:27 /dev/md0 6976558760 5146951752 1477984048 78% /data1 -4096
2018-11-22 20:11:28 /dev/md0 6976558760 5146968136 1477967664 78% /data1 -16384
2018-11-22 20:11:29 /dev/md0 6976558760 5146972232 1477963568 78% /data1 -4096
2018-11-22 20:11:30 /dev/md0 6976558760 5146988848 1477946952 78% /data1 -16616
2018-11-22 20:11:31 /dev/md0 6976558760 5146996808 1477938992 78% /data1 -7960
2018-11-22 20:11:32 /dev/md0 6976558760 5147009096 1477926704 78% /data1 -12288
2018-11-22 20:11:33 /dev/md0 6976558760 5147009096 1477926704 78% /data1 0
2018-11-22 20:11:34 /dev/md0 6976558760 5147017288 1477918512 78% /data1 -8192
2018-11-22 20:11:35 /dev/md0 6976558760 5147029576 1477906224 78% /data1 -12288
2018-11-22 20:11:36 /dev/md0 6976558760 5147033672 1477902128 78% /data1 -4096
2018-11-22 20:11:37 /dev/md0 6976558760 5147037772 1477898028 78% /data1 -4100
2018-11-22 20:11:38 /dev/md0 6976558760 5147045964 1477889836 78% /data1 -8192
2018-11-22 20:11:39 /dev/md0 6976558760 5147066444 1477869356 78% /data1 -20480
2018-11-22 20:11:40 /dev/md0 6976558760 5147070540 1477865260 78% /data1 -4096
2018-11-22 20:11:41 /dev/md0 6976558760 5147074636 1477861164 78% /data1 -4096
2018-11-22 20:11:42 /dev/md0 6976558760 5147091020 1477844780 78% /data1 -16384
2018-11-22 20:11:43 /dev/md0 6976558760 5147099212 1477836588 78% /data1 -8192

bash计算上下行数据差值

只看某个文件的变化:

for i in {1..60000}; do echo "`date +'%F %T'` `ls -l access_log.181124` "; sleep 1; done | awk '{a[NR]=$7; print $0,a[NR]-a[NR-1]}'