After a long quest for useful tint2 "executors" or conky tips, I share with you my findings and own creations. I wanted to get infos about RAM, CPU and battery, with direct read from existing files - without any external command, in order to be as frugal as possible. I included in the short scripts that follow some core commands that should work on every system (except for temperature and fan, which seem to be very dependent on hardware and kernel versions), and some other alternatives or ideas that are commented.
tint2 is a great toolbar program that you can customize, very useful for MX-fluxbox users (but you can try it on xfce of course). Executors are little programs that can display useful infos on your tint2 toolbar (so you can virtually display every info you find nice to get).
For memory, with 2 figures : used by apps memory, and total used memory (better to know if you can afford to open new apps)
Code: Select all
#!/bin/bash
# first number : the memory which is used by processes, got through /proc/meminfo file. Same figures as htop or conky, good to know how much RAM are used by opened applications.
# second number : the percentage of globally used memory, including system use . Is greater than first number. Better way to know if you can afford opening new applications.
mem=$(cat /proc/meminfo | awk ' FNR<=5 || FNR>=21 {a[NR]=$2} END {printf "%.2f Gio | %.0f%\n", (a[1]-a[2]-a[4]-a[5]-a[24]+a[21])/(1024*1024), (a[1]-a[3])*100/a[1]}' )
echo /usr/share/icons/Papirus/24x24/panel/indicator-sensors-memory.svg
echo $mem
# to get the used memory through /proc/meminfo file - strict definition, but different from htop or conky.
#mem=$(cat /proc/meminfo | awk 'FNR<=6 {a[NR]=$2} END {printf "%.2f Go\n", (a[1]-a[2]-a[4]-a[5]) / (1024*1024)}' )
# to get the used + shared memory through free command
# I added shared memory to get the same number as htop or conky, even if it seems strange.
#mem2=`free | awk '/Mem/ {printf "%.2f Gio\n", ($3+$5) / (1024*1024)}'`
# to calculate available mem, from https://unix.stackexchange.com/questions/261247/how-can-i-get-the-amount-of-available-memory-portably-across-distributions
# it is quite the same as MemAvailable, so not useful to use except to check or test.
#mem3=$(awk -v low=$(grep low /proc/zoneinfo | awk '{k+=$2} END {print k}') '{a[$1]=$2} END { printf "%.2f Go", ( a["MemFree:"]+a["Active(file):"]+a["Inactive(file):"]+a["SReclaimable:"]-(12*low) ) / (1024*1024) }' /proc/meminfo )
# About used memory calculation from /proc/meminfo, see https://access.redhat.com/solutions/406773#comment-1339671 and https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
# used memory = MemTotal - (MemFree + cached + buffers + SReclaimable) + shared mem.
# I added ShMem (shared memory) to get the same number as htop or conky, even if it seems strange.
Code: Select all
#!/bin/bash
# to get current CPU and system usage (on a 3 seconds period) directly from /proc/stat
cpu=$( (head -n1 /proc/stat ; sleep 3; head -n1 /proc/stat) | awk '{u[NR]=$2+$3+$4+$6+$7+$8+$9; t[NR]=$u[NR]+$5} END {printf "%.0f%", (u[2]-u[1])*100/(t[2]-t[1]) }' )
# to get cpu temperature. Could have to find the correct file for your hardware, kernel and OS combination
temp=$(cat /sys/devices/platform/coretemp.0/hwmon/hwmon6/temp1_input | cut -c-2)
echo /usr/share/icons/Papirus-Dark/symbolic/devices/proc-symbolic.svg
echo " $cpu | $temp°C "
#fi
# to check in the sensors command output for a line with "Package" and extract the temperature value
#temp=`sensors | awk '/Package/ {gsub ("+","");split($4,var,".");print var[1] "°C"}'`
# to get freq from the first cpu core only
#freq=$(cat /proc/cpuinfo | awk '/cpu MHz/ && FNR<=28 {split($4,var,"."); printf "%.1f Ghz\n", var[1]/1000}')
# to get current CPU and system usage (on a 1 second period) directly from /proc/stat
#cpu=$( (head -n1 /proc/stat ; sleep 1; head -n1 /proc/stat) | awk '{u[NR]=$2+$3+$4+$6+$7+$8+$9; t[NR]=$u[NR]+$5} END {printf "%.0f %", (u[2]-u[1])*100/(t[2]-t[1]) }' )
# to get all cpu cores frequencies from /cpufreq/scaling_cur_freq and calculate the mean value. Should work with any cpu cores number.
#freq=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq | awk '{ sum += $1 } END { printf "%.1f GHz\n", sum/FNR/1000000 }')
# to get all cpu cores frequencies from /proc/cpuinfo file and calculate the mean value. Should work with any cpu cores number.
#freq=($cat /proc/cpuinfo | awk '/cpu MHz/ { split($4,var,".") ; sum += var[1] ; nb += 1} END { printf "%.1f Ghz\n", sum/nb }')
# to get number of cpu cores
#nb=$(cat /proc/cpuinfo | awk '/siblings/ && FNR <= 28 {print $3} ')
# to get cpu load from /proc/loadavg. Three values exist for 1, 5 or 15 minutes periods.
#load1=$(cat /proc/loadavg | awk ' {printf "%.0f", $1 $2 }')
#load5=$(cat /proc/loadavg | awk ' {printf "%.0f", $2 }')
#load15=$(cat /proc/loadavg | awk ' {printf "%.0f", $3* }')
# to display load only if greater than X
#if [ $load1 -lt X ] ; then load1final="" ; else load1final=" | $load1%" ; fi
# to get fan speed. Could work... but depends on hardware and kernel compatibility
#fan=$(cat /sys/class/hwmon/hwmon5/fan2_input)
#fan1=$(cat /sys/class/hwmon/hwmon5/fan1_input)
Code: Select all
#!/bin/bash
# for use with connman as connectivity manager, through connmanctl tool
state=$(connmanctl state | awk 'FNR == 1 {print $3}')
network=$(connmanctl services | awk 'FNR == 1 {print $2}' | cut -c-10)
if [ $state == "online" ]; then
echo /usr/share/icons/Papirus/16x16/panel/knemo-network-idle.svg
echo " "$network
elif [ $state == "ready" ]; then
echo /usr/share/icons/Papirus/16x16/panel/knemo-network-error.svg
echo " "$network
else
echo /usr/share/icons/Papirus/16x16/panel/knemo-monitor-offline.svg
fi
# for use with NetworkManager, through nmcli tool
#type=$(nmcli d | awk 'FNR == 2 {print $2}')
#state=$(nmcli d | awk 'FNR == 2 {print $3}')
#network=$(nmcli d | awk 'FNR == 2 {print $4}')
#if [ $type == "ethernet" ]; then
# if [ $state == "connected" ]; then
# echo ~/.config/tint2/Executors/Icons/network-wired.svg
# echo "eth" $network
# else
# echo ~/.config/tint2/Executors/Icons/network-wired-offline.svg
# echo "unconnected"
# fi
#elif [ $type == "wifi" ]; then
# if [ $state == "connected" ]; then
# echo /usr/share/icons/Papirus-Dark/16x16/panel/knemo-network-idle.svg
# echo " " $network
# else
# echo ~/.config/tint2/Executors/Icons/network-wireless-offline-symbolic.svg
# echo "unconnected"
# fi
#fi
# for use with all connectivity manager. could find info on wifi and ethernet connection, but not the name of the network.
#statewifi=$(cat /sys/class/net/wlan0/operstate)
#stateether=$(cat /sys/class/net/eth0/operstate)
Code: Select all
#!/bin/bash
# to get battery info directly from /sys/class/power_supply file system
state=$(cat /sys/class/power_supply/AC/online)
bat=$(cat /sys/class/power_supply/BAT0/capacity)
curr=$(cat /sys/class/power_supply/BAT0/current_now)
#charge=$(cat /sys/class/power_supply/BAT0/charge_now)
#full=$(cat /sys/class/power_supply/BAT0/charge_full)
#bat=$((100*charge/full))
if [ $state == 0 ]; then
volt=$(cat /sys/class/power_supply/BAT0/voltage_now)
puiss=$( echo "scale=2; $curr*$volt/1000000000000" | bc -l)
echo /usr/share/icons/Papirus/16x16/panel/battery-full.svg
#echo " $bat% | $curr mA | $volt V | $puiss W"
echo " $bat% | $puiss W"
else
curr1=$( echo "scale=2; $curr/1000000" | bc -l)
echo /usr/share/icons/Papirus/16x16/panel/battery_plugged.svg
if [ $curr -lt 10000 ]; then
echo " $bat% | stable "
else
echo " $bat% | charge - $curr1 A"
fi
fi
# to get battery info from acpi command
#state=$(acpi | awk 'FNR == 1 {print $3}')
#bat=`acpi | awk '{print $4}'| cut -c-3`
#if [ $state == "Discharging," ]; then
# echo /usr/share/icons/Papirus-Dark/symbolic/devices/ac-adapter-symbolic.svg
#else
# echo /usr/share/icons/Papirus-Dark/symbolic/devices/ac-adapter-symbolic.svg
#fi
#echo " $bat"
# Alternatives ways to get current
#curr=`cat /sys/class/hwmon/hwmon2/curr1_input`
#curr=`sensors -Au | awk '/curr1_input/ && NR>=10 {printf "%.0f mA\n", $2*1000}'`
#curr=`sensors -Au | awk '/curr1_input/ && NR>=10 {gsub ("+","");split($2,var,".");print var[2] " mA"}'`