2020-06-01 08:10:10 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
get_percent()
|
|
|
|
{
|
2020-06-03 04:55:14 +02:00
|
|
|
case $(uname -s) in
|
2020-06-01 08:10:10 +02:00
|
|
|
Linux)
|
|
|
|
percent=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
|
|
|
|
echo $percent
|
|
|
|
;;
|
|
|
|
|
|
|
|
Mac)
|
2020-06-01 16:39:17 +02:00
|
|
|
percent=$(ps -A -o %cpu | awk '{s+=$1} END {print s "%"}')
|
2020-06-01 17:53:16 +02:00
|
|
|
echo $percent
|
2020-06-01 08:10:10 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
Windows)
|
|
|
|
# TODO - windows compatability
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
2020-06-03 04:55:14 +02:00
|
|
|
cpu_percent=$(get_percent)
|
2020-06-01 08:10:10 +02:00
|
|
|
echo "CPU $cpu_percent"
|
2020-06-02 01:27:15 +02:00
|
|
|
sleep 10
|
2020-06-01 08:10:10 +02:00
|
|
|
}
|
|
|
|
#run main driver
|
|
|
|
main
|