Raspberry Pi B+ CPU load monitor bash script source code

This script helps you monitor CPU Load  of your RPi every five minutes. Values are exported to a .csv file and location of your choice.

You can stop and start the script whenever you want. Values will be written after the last one, if you select the same file.

Create a file on your Desktop and name it for example cpuload.sh. Open file and copy/paste and save the code below.

(run the script in terminal with this command: bash /yourlocation/cpuload.sh).

#!/bin/bash

#Raspberry Pi CPU Load Monitor
#Built by Zeus-www.thelinuxterminal.com
#For more info, drop a mail: office@thelinuxterminal.com

read -p "Enter location and filename (e.g. /root/Desktop/cpu_load.csv): " cpuload
cpu_load="$cpuload"
get_date=$(date +%d/%m/%y)
get_time=$(date +%H:%M)
if [ ! -f $cpu_load ];
then
echo "Date,CPU Load" >> $cpu_load
while :
do
cpuLoad=$(ps aux | awk {'sum+=$3;print sum'} | tail -n 1)
get_date_time=$(date "+%Y/%m/%d %H:%M:%S")
echo ""$get_date_time","$cpuLoad""
sleep 300
done >> $cpu_load
else
while :
do
cpuLoad=$(ps aux | awk {'sum+=$3;print sum'} | tail -n 1)
get_date_time=$(date "+%Y/%m/%d %H:%M:%S")
echo ""$get_date_time","$cpuLoad""
sleep 300
done >> $cpu_load
fi

Creative Commons License
Raspberry Pi B+ CPU load monitor bash script source code by The Linux Terminal is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.