我如何获取实时值以在 BASH 中制作自己的脚本,特别如附件所示
我正在尝试在 BASH 中编写我自己的跟踪,如附件中所示。
特别是我需要跟踪接收和发送数据的网络历史记录。我在哪里可以获得这些网络发送/接收值,它是在文件中还是来自 Linux 中的某些命令?
使用 BASH 我试图实现类似如下的东西:
例如:
/* My 10 seconds timer */
t = new javax.swing.Timer(10000, new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
}
});
跟进:(好网站:http://www.debianhelp.co.uk/networktools1.htm)
$ sudo apt-get install bwm-ng;
yum -y install bwm;
# Show me only plain mode
$ bwm-ng -o plain
bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
/proc/net/dev
| iface Rx Tx Total
==============================================================================
lo: 88803.53 KB/s 88803.53 KB/s 88803.53 KB/s
eth0: 0.13 KB/s 0.13 KB/s 0.13 KB/s
------------------------------------------------------------------------------
total: 88803.66 KB/s 88803.66 KB/s 88803.66 KB/s
# Show only the interface that i need to see
$ bwm-ng -o plain -I eth0
bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
/proc/net/dev
| iface Rx Tx Total
==============================================================================
eth0: 0.13 KB/s 0.13 KB/s 0.13 KB/s
------------------------------------------------------------------------------
total: 0.13 KB/s 0.13 KB/s 0.13 KB/s
# Show only in MB format or KB format
# by skiping -d will default show as KB
$ bwm-ng -o plain -d
bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
/proc/net/dev
/ iface Rx Tx Total
==============================================================================
lo: 85.79 MB/s 85.79 MB/s 85.79 MB/s
eth0: 246.58 B/s 246.58 B/s 246.58 B/s
------------------------------------------------------------------------------
total: 85.79 MB/s 85.79 MB/s 85.79 MB/s
$ bwm-ng -o plain -N -d | grep total:
total: 0.00 B/s 0.00 B/s 0.00 B/s
total: 1.28 MB/s 1.28 MB/s 1.28 MB/s
total: 1.19 MB/s 1.19 MB/s 1.19 MB/s
total: 1.19 MB/s 1.19 MB/s 1.19 MB/s
# another tool i used apt-get install vnstat
# bwm-ng was doing wrong strange on other interfaces but this one
# now showing correct
$ vnstat -u -i lo
$ vnstat -u -i eth0
$ vnstat
$ iftop -i eth0
I am trying to write in BASH my own tracking such as shown in the attachment.
Specially i need to track the Network History Recieving and Sending data. Where i can get those Network send/receive values, is it in a file or is that comes out from some commands in Linux?
Using BASH i am trying to implement something similar as below:
ex:
/* My 10 seconds timer */
t = new javax.swing.Timer(10000, new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
}
});
Follow up: (good site: http://www.debianhelp.co.uk/networktools1.htm)
$ sudo apt-get install bwm-ng;
yum -y install bwm;
# Show me only plain mode
$ bwm-ng -o plain
bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
/proc/net/dev
| iface Rx Tx Total
==============================================================================
lo: 88803.53 KB/s 88803.53 KB/s 88803.53 KB/s
eth0: 0.13 KB/s 0.13 KB/s 0.13 KB/s
------------------------------------------------------------------------------
total: 88803.66 KB/s 88803.66 KB/s 88803.66 KB/s
# Show only the interface that i need to see
$ bwm-ng -o plain -I eth0
bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
/proc/net/dev
| iface Rx Tx Total
==============================================================================
eth0: 0.13 KB/s 0.13 KB/s 0.13 KB/s
------------------------------------------------------------------------------
total: 0.13 KB/s 0.13 KB/s 0.13 KB/s
# Show only in MB format or KB format
# by skiping -d will default show as KB
$ bwm-ng -o plain -d
bwm-ng v0.6 (delay 0.500s); press 'ctrl-c' to end this
/proc/net/dev
/ iface Rx Tx Total
==============================================================================
lo: 85.79 MB/s 85.79 MB/s 85.79 MB/s
eth0: 246.58 B/s 246.58 B/s 246.58 B/s
------------------------------------------------------------------------------
total: 85.79 MB/s 85.79 MB/s 85.79 MB/s
$ bwm-ng -o plain -N -d | grep total:
total: 0.00 B/s 0.00 B/s 0.00 B/s
total: 1.28 MB/s 1.28 MB/s 1.28 MB/s
total: 1.19 MB/s 1.19 MB/s 1.19 MB/s
total: 1.19 MB/s 1.19 MB/s 1.19 MB/s
# another tool i used apt-get install vnstat
# bwm-ng was doing wrong strange on other interfaces but this one
# now showing correct
$ vnstat -u -i lo
$ vnstat -u -i eth0
$ vnstat
$ iftop -i eth0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:简单的方法:您始终可以使用 mrtg 或 cacti 而不是自己做。
否则...
每 2 秒获取字节输入和字节输出(按 ctrl+c 使其停止):
您将得到如下输出:
这些值是为安装默认路由的设备获取的。
EDIT: the easy way: you could always use mrtg or cacti instead of doing it yourself.
otherwise...
getting the bytes in and the bytes out, each 2 seconds (hit ctrl+c to make it stop):
you'll get output like this:
the values are obtained for the device where the default route is installed.
您可以编写自己的脚本来解析:
Yon can write your own script to parse :