Cron
如何將 slurm 命令的輸出保存到文件中?
我已經安裝了 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 #####################################
任何幫助,將不勝感激。
我想唯一確定的方法是使用 screen 或 tmux 之類的程序。
所以,你可以讓你的 slurm 在螢幕上執行,從螢幕會話中分離,然後執行
screen -X hardcopy /tmp/tmpfile cat /tmp/tmpfile >> final_destionation.txt
在一個 cron
如果您需要擷取多個會話,您可以使用更多選項修改螢幕,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
有很多空行,所以一些 grepping 不會受到傷害,但這是一個開始