这是我写的网卡流量统计脚本,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]
数据统计,还能更精简吗(以及其它语言)?
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
- ChenFengyuan
- 帖子: 770
- 注册时间: 2008-03-23 0:39
Re: 数据统计,还能更精简吗(以及其它语言)?
nload ?
/sbin/ifconfig?

/sbin/ifconfig?

- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 数据统计,还能更精简吗(以及其它语言)?
nload 是什么?ChenFengyuan 写了:nload ?
/sbin/ifconfig?
ifconfig 只能看当时,我要看历史。