数据统计,还能更精简吗(以及其它语言)?

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

数据统计,还能更精简吗(以及其它语言)?

#1

帖子 lilydjwg » 2012-01-29 21:32

这是我写的网卡流量统计脚本,zsh+awk,太长了。谁来写个纯 shell 版、纯 awk 版、Perl / Ruby / Haskell 等语种的版本?
[bash]
#!/bin/zsh

zgrep -P 'pppd\[\d+\]: Sent' /var/log/everything.log*(Om) | cut -d: -f2- | awk '
function ceiling(x) {
return (x == int(x)) ? x : int(x)+1;
}
function toM(x) {
return x / 1024.0 / 1024.0;
}
{
a = toM($7);
b = toM($10);
printf("%s %s %s: %4.1fMiB sent, %4.1fMiB received.\n", $1, $2, $3, a, b);
s += $7; r += $10;
sm += ceiling(a); rm += ceiling(b);
}
END {
printf("Total by bytes: %4.1fMiB sent, %4.1fMiB received.\n", toM(s), toM(r));
printf("Total by MiB : %4.1fMiB sent, %4.1fMiB received.\n", sm, rm);
}
'
[/bash]
头像
ChenFengyuan
帖子: 770
注册时间: 2008-03-23 0:39

Re: 数据统计,还能更精简吗(以及其它语言)?

#2

帖子 ChenFengyuan » 2012-01-30 16:20

nload ?
/sbin/ifconfig?
:em03
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 数据统计,还能更精简吗(以及其它语言)?

#3

帖子 lilydjwg » 2012-01-30 16:29

ChenFengyuan 写了:nload ?
/sbin/ifconfig?
:em03
nload 是什么?
ifconfig 只能看当时,我要看历史。
回复