You are not logged in.

#1 2019-06-01 21:59:17

dxxvi
Member
Registered: 2011-07-23
Posts: 126

Ask for opinions to print some info on a tint2 panel

Hi All,

I'm using tint2 and want to print some system information on a tint2 panel (because I want to print on a tint2 panel, so conky is not suitable, is it?). This is what I want to print:

%memory_usage %cpu_usage app_name_using_cpu_most app_name_using_cpu_second wifi_network_name ↑ transmitting_speed ↓ receiving_speed %battery_remaining (the color will be changed accordingly to charging or discharging).

For %memory_usage %cpu_usage app_name_using_cpu_most app_name_using_cpu_second, I intend to run top -b -d 1 - n 3 | grep -A8 "top - " | tail -n 7 which gives me this

%Cpu(s):  0.1 us,  0.1 sy,  0.0 ni, 99.8 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  15741.4 total,  12520.1 free,    607.9 used,   2613.4 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.  14521.2 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
  480 root     -51   0       0      0      0 S   1.0   0.0   0:00.06 irq/51-iwlwifi:
 3169 ly        20   0   13260   3472   3112 R   1.0   0.0   0:00.02 top

then do some string manipulation in bash to get the data.
ru
For wifi_network_name ↑ transmitting_speed ↓ receiving_speed, I intend to run

nmcli connection show | grep my_network_interface_name

and then some string manipulation again to get the wifi_network_name. For the rx/tx speed,

vnstat --traffic 2 -i wlp0s20f3 --rateunit 0 | tail -n 3 | head -n 2
      rx               0 B/s             0 packets/s
      tx               0 B/s             0 packets/s

The battery info is the result of the acpi command.

As you can see, it's doable but with a lot of string manipulations in bash. Is there any simpler way to get all the info I need?

Regards.

Offline

#2 2019-06-02 00:39:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: Ask for opinions to print some info on a tint2 panel

Yes, much simpler ways.  Just think it through.  First there is (almost?) never a need to pipe from grep to tail or through any multiple text processing tools.  And there's definitely no need to do additional string manipulation in the shell after that.  Just ask for what you want in the first place.  For example, ditch the ps-to-grep-to-tail-to-bash approach and try this:

ps -o comm= -k -%cpu | head -3

Or if you'll want some formatting of it, e.g.:

/bin/ps -o comm= -k -%cpu | sed '1,2 s/$/ |/;3q'

For network info, you'd probably want to explore /proc/net/*, but in any case, never do a "tail -n 3 | head -n 2" as - at worst - that's just "sed -n '3,4p'", but in this case, the head really does nothing as it removes a blank line.  The blank line goes away anyways when you linearize it for display on tint2.  And in this case, I'd bet there's a flag to vnstat to inhibit printing the header which is all your tail command seems to do

But to your original question, conky would work just fine too - it can quite easily give text output for piping to other display tools.

Also note that most of the tools you mention all gather raw data from the system and present it in a "user friendly" way which you then in turn planned on using yet other tools to strip out that user-friendly presentation to get  back to the raw data.  Cut out the middle men.

Last edited by Trilby (2019-06-02 01:33:21)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB