我已经安装了 slurm 命令来跟踪接口消耗的数据量apt install slurm
我的黄金是将其输出保存到文件中,我编写了这个脚本来让我做到这一点,但我没有得到预期的结果。
#!/bin/bash
echo "#####################################"
date "+%F %H:%M:%S :: snapshot on interface"
timeout 5s slurm -s -i eno1 >> /home/trackeNIC.log;
我添加这个作业来运行脚本
* * * * * bash /home/trackeNIC.sh >> /home/trackeNIC.log
我得到的结果是:
#####################################
2020-05-15 15:02:01 :: snapshot on interface
#####################################
2020-05-15 15:03:01 :: snapshot on interface
#####################################
我期望类似的东西:
#####################################
2020-05-15 15:02:01 :: snapshot on interface
-= slurm 0.4.3 =-
x
x
x
x x
xxxx
xxxx
xx x
x x
x
x
Active Interface: eno1 Interface Speed: unknown
Current RX Speed: 141.12 KB/s Current TX Speed: 17.63 KB/s
Graph Top RX Speed: 876.31 KB/s Graph Top TX Speed: 32.47 KB/s
Overall Top RX Speed: 876.31 KB/s Overall Top TX Speed: 32.47 KB/s
Received Packets: 24045657 Transmitted Packets: 14187466
GBytes Received: 21.377 GB GBytes Transmitted: 1.381 GB
Errors on Receiving: 0 Errors on Transmission: 0
#####################################
2020-05-15 15:03:01 :: snapshot on interface
-= slurm 0.4.3 =-
x
x
x
x x
xxxx
xxxx
xx x
x x
x
x
Active Interface: eno1 Interface Speed: unknown
Current RX Speed: 141.12 KB/s Current TX Speed: 17.63 KB/s
Graph Top RX Speed: 876.31 KB/s Graph Top TX Speed: 32.47 KB/s
Overall Top RX Speed: 876.31 KB/s Overall Top TX Speed: 32.47 KB/s
Received Packets: 24045657 Transmitted Packets: 14187466
GBytes Received: 26.377 GB GBytes Transmitted: 2.381 GB
Errors on Receiving: 0 Errors on Transmission: 0
#####################################
任何帮助,将不胜感激。
答案1
我想唯一可靠的方法是使用 screen 或 tmux 等程序。
因此,您可以让 slurm 在屏幕中运行,从屏幕会话中分离出来,然后运行
screen -X hardcopy /tmp/tmpfile
cat /tmp/tmpfile >> final_destionation.txt
在一个 cron 中
如果您需要捕获多个会话,您可以使用更多选项修改 screen,man screen 可以帮助您。
结果如下:
-= slurm 0.4.3 on catscrash-desktop =-
x
x
x
x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x x x xx xx xx
x x x x
x x x x
Active Interface: enp3s0 Interface Speed: unknown
Current RX Speed: 0.73 KB/s Current TX Speed: 1.08 KB/s
Graph Top RX Speed: 211.54 KB/s Graph Top TX Speed: 15.46 KB/s
Overall Top RX Speed: 236.80 KB/s Overall Top TX Speed: 22.95 KB/s
Received Packets: 15711309 Transmitted Packets: 8187879
GBytes Received: 14.754 GB GBytes Transmitted: 1.586 GB
Errors on Receiving: 0 Errors on Transmission: 0
-= slurm 0.4.3 on catscrash-desktop =-
x
x
x
x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x x x x x
x x x
x x
x
Active Interface: enp3s0 Interface Speed: unknown
Current RX Speed: 2.15 KB/s Current TX Speed: 0.57 KB/s
Graph Top RX Speed: 226.49 KB/s Graph Top TX Speed: 18.00 KB/s
Overall Top RX Speed: 14187.07 KB/s Overall Top TX Speed: 870.02 KB/s
Received Packets: 15760792 Transmitted Packets: 8215865
GBytes Received: 14.810 GB GBytes Transmitted: 1.590 GB
Errors on Receiving: 0 Errors on Transmission: 0
有很多空行,所以一些 grep 不会有什么坏处,但这是一个开始