You are not logged in.
Hello
i try to found any command line for terminal equivalent as {cpu cpu0} in conky to have cpu charge in a console &
to try it in a script
@+
Linuxmint 22.1 Xia xfce & mageia 9 XFCE on ssd hp pavilion g7
Xubuntu 18.04 lts & 24.04 lts on ASUS Rog STRIX
Offline
Maybe?
apt policy sysstat
sysstat:
Installiert: (keine)
Installationskandidat: 11.4.3-2
Versionstabelle:
11.4.3-2 500
500 https://deb.debian.org/debian stretch/main amd64 Packages
Offline
mpstat - which I think is part of package of utilities in Debian; maybe sysstat.
It's used for the default cpu_usage script for i3blocks:
#!/usr/bin/perl
#
# Copyright 2014 Pierre Mavro <deimos@deimos.fr>
# Copyright 2014 Vivien Didelot <vivien@didelot.org>
# Copyright 2014 Andreas Guldstrand <andreas.guldstrand@gmail.com>
#
# Licensed under the terms of the GNU GPL v3, or any later version.
use strict;
use warnings;
use utf8;
use Getopt::Long;
# default values
my $t_warn = 50;
my $t_crit = 80;
my $cpu_usage = -1;
sub help {
print "Usage: cpu_usage [-w <warning>] [-c <critical>]\n";
print "-w <percent>: warning threshold to become yellow\n";
print "-c <percent>: critical threshold to become red\n";
exit 0;
}
GetOptions("help|h" => \&help,
"w=i" => \$t_warn,
"c=i" => \$t_crit);
# Get CPU usage
$ENV{LC_ALL}="en_US"; # if mpstat is not run under en_US locale, things may break, so make sure it is
open (MPSTAT, 'mpstat 1 1 |') or die;
while (<MPSTAT>) {
if (/^.*\s+(\d+\.\d+)\s+$/) {
$cpu_usage = 100 - $1; # 100% - %idle
last;
}
}
close(MPSTAT);
$cpu_usage eq -1 and die 'Can\'t find CPU information';
# Print short_text, full_text
printf "%.2f%%\n", $cpu_usage;
printf "%.2f%%\n", $cpu_usage;
# Print color, if needed
if ($cpu_usage >= $t_crit) {
print "#FF0000\n";
exit 33;
} elsif ($cpu_usage >= $t_warn) {
print "#FFFC00\n";
}
exit 0;
You can find some bash scripts using it if you check out the i3, dwm (tiling wm's in general) threads and see how their status bars are set up.
There is also the psutil suite if you want to go with python.
Last edited by PackRat (2019-07-10 17:04:33)
You must unlearn what you have learned.
-- yoda
Offline
hello
I’m trying to get this out of the terminal with this commande
top -n1 | grep 'Cpu(s)'| awk '{print $2;}' | sed -e 's/id,//g'
that donne this
~/Bureau$ top -n1 | grep 'Cpu(s)'| awk '{print $2;}' | sed -e 's/id,//g'
0,9
i would just the number(s) before the ,
Last edited by loutch (2019-07-11 07:06:48)
Linuxmint 22.1 Xia xfce & mageia 9 XFCE on ssd hp pavilion g7
Xubuntu 18.04 lts & 24.04 lts on ASUS Rog STRIX
Offline
how about this?
USER@HOST[~]$ top -n1 | grep 'Cpu(s)'| awk '{print $2;}' | cut -c1-1
5
naik --greetz
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen Codeberg
Offline
how about this?
USER@HOST[~]$ top -n1 | grep 'Cpu(s)'| awk '{print $2;}' | cut -c1-1 5
naik --greetz
i try the cut -c1-2 ( done 7, work great with number who begin with 10 ) & c1-3 (done 8,1 or 12,)
Last edited by loutch (2019-07-11 09:09:29)
Linuxmint 22.1 Xia xfce & mageia 9 XFCE on ssd hp pavilion g7
Xubuntu 18.04 lts & 24.04 lts on ASUS Rog STRIX
Offline
I have this
# cpu usage in percents
tmp=$(ps -A -o pcpu | tail -n+2 | paste -sd+ | bc)
cpu=$(awk_round 0 "$tmp")
echo "$cpu% cpu used"
Offline
#!/bin/bash
# calculates cpu usage from values found in /proc/stat
delay=1 # 1 second between reads
color=''
# optional eyecandy
#~ tput civis
#~ trap 'tput cnorm' EXIT
# sleep as a builtin
for file in /usr/lib*/bash/sleep; do
[ -r "$file" ] && enable -f "$file" sleep && break
done
# Portable enough?
while :; do
# Get the first line with aggregate of all CPUs
read -r -a cpu_now </proc/stat
# Get all columns but skip the first (which is the "cpu" string)
cpu_sum="${cpu_now[@]:1}"
# Replace the column seperator (space) with +
cpu_sum="${cpu_sum// /+}"
# Get the delta between two reads
cpu_delta=$((cpu_sum - cpu_last_sum))
# Get the idle time Delta
cpu_idle=$((cpu_now[4]- cpu_last[4]))
# Calc time spent working
cpu_used=$((cpu_delta - cpu_idle))
# Calc percentage
cpu_usage=$((100 * cpu_used / cpu_delta))
# Keep this as last for our next read
cpu_last=("${cpu_now[@]}")
cpu_last_sum=$cpu_sum
# optional eyecandy
#~ case $cpu_usage in
#~ [5-7]?) color='\e[33m' ;; # yellow
#~ [8-9]?|100) color='\e[31m' ;; # red
#~ esac
printf "\r\E[0KCPU ${color}%02d%%\E[0m" $cpu_usage
# Wait a second before the next read
sleep "$delay"
done
Offline