0

I have installed slurm command to track the amount of data consumed by an interface apt install slurm

My gold is to save its output into a file, I wrote this script to let me do that, but I did not get the expected results.

#!/bin/bash
echo "#####################################"
date "+%F %H:%M:%S :: snapshot on interface"
timeout 5s slurm -s -i eno1 >> /home/trackeNIC.log;

I add this job for running the script

* * * * * bash /home/trackeNIC.sh >> /home/trackeNIC.log

The result I got is :

#####################################
2020-05-15 15:02:01 :: snapshot on interface
#####################################
2020-05-15 15:03:01 :: snapshot on interface
#####################################

I expect something like :

#####################################
    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
    #####################################

Any help would be appreciated.

4
  • Does it help if you use slurm with the full path to the slurm executable? The PATH variable may well be different in the environment that cron jobs are executed compared to your interactive shell environment.
    – Kusalananda
    May 15, 2020 at 15:50
  • Even timeout 5s slurm -s -i eno1 >> /home/trackeNIC.log; does not append the output into the file.
    – Youssef
    May 15, 2020 at 18:00
  • Find the full paths of both timeout and slurm with command -v timeout and command -v slurm in an interactive shell. Then use those paths when you call those tools in your script. Does that make it work?
    – Kusalananda
    May 15, 2020 at 18:14
  • @Kusalananda even with the full paths it gives the same thing.
    – Youssef
    May 18, 2020 at 13:31

1 Answer 1

0

I guess the only sure way, would be to use a program like screen or tmux.

So, you could keep your slurm running in screen, detach from the screen session and then run

screen -X hardcopy /tmp/tmpfile
cat /tmp/tmpfile >> final_destionation.txt

in a cron

you can modify screen with more options if you have multiple sessions that you need to capture, man screen helps there.

The result looks like this:

                     -= 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


There's a lot of empty lines, so some grepping won't hurt, but it's a start

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .