Script sends CPU temps to file

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
scientist
Posts: 860
Joined: Sat 23 May 2015, 08:21

Script sends CPU temps to file

#1 Post by scientist »

This works but distorts CPUtemps icon a bit. :-)
#!/bin/bash
#
# Linux Puppy 6.3.0 SiegeWorks 2016 A.P.K.
#
# Send CPU temps to file every 15 minutes
# NOTE: This messes with icon for CPUtemp
count=1
done=0

while [ $count -le 10 ]
do
sleep 1
(( count++ ))
if [ $count == 5 ]
then
continue
fi
date "+ %m/%d/%y %r" >> ~/Documents/CPU_TEMPS.txt
sensors -f >> ~/Documents/CPU_TEMPS.txt
sleep 900
done
Thanks,
Andy


Slacko 6.3.0 FULL INSTALL
JWM
File Manager - Thunar

ebisu
Posts: 176
Joined: Wed 25 Sep 2013, 05:06

#2 Post by ebisu »

done=0 looks wrong. And why does it avoid writing when count=5? Who wrote this?

scientist
Posts: 860
Joined: Sat 23 May 2015, 08:21

#3 Post by scientist »

ebisu wrote:done=0 looks wrong. And why does it avoid writing when count=5? Who wrote this?
I wrote it.

Interested in any suggestions you have.

Newer version.
#!/bin/bash
#
# Linux Puppy 6.3.0 SiegeWorks 2016 A.P.K.
#
# Send CPU temps to file every 15 minutes
# NOTE: This messes with icon for CPUtemp
count=1
done=0

while [ $count -le 10 ]
do
sleep 1
(( count++ ))
if [ $count == 5 ]
then
continue
fi
date "+ %m/%d/%y %r" >> ~/Documents/CPU_TEMPS.txt
sensors -f >> ~/Documents/CPU_TEMPS.txt
sleep 900
done
#!/bin/bash
#
# Linux Puppy 6.3.0 SiegeWorks 2016 A.P.K.
#
# Send battery state to file every 15 minutes
# Useful in determining how long your battery will actually last
#
count=1
done=0

echo Laptop Battery Status Report >> Battery_State.txt
while [ $count -le 10 ]
do
sleep 1
(( count++ ))

date "+ %m/%d/%y %r" >> Battery_State.txt
grep remaining /proc/acpi/battery/*/state >> Battery_State.txt
#
grep full /proc/acpi/battery/*/info >> Battery_State.txt
#
grep charging /proc/acpi/battery/*/state >> Battery_State.txt
sleep 900
done
Thanks,
Andy


Slacko 6.3.0 FULL INSTALL
JWM
File Manager - Thunar

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#4 Post by Flash »

I suggest that you try a dialog, where you answer questions that other people ask, and maybe explain what you're doing in the script. Terse and cryptic just doesn't cut it.

scientist
Posts: 860
Joined: Sat 23 May 2015, 08:21

#5 Post by scientist »

Flash wrote:I suggest that you try a dialog, where you answer questions that other people ask, and maybe explain what you're doing in the script. Terse and cryptic just doesn't cut it.
I have answered all questions that I am aware of.

My scripts also have notes that explain what the script does.
# Send battery state to file every 15 minutes
# Useful in determining how long your battery will actually last
Thanks,
Andy


Slacko 6.3.0 FULL INSTALL
JWM
File Manager - Thunar

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#6 Post by Flash »

ebisu wrote:...why does it avoid writing when count=5?...

scientist
Posts: 860
Joined: Sat 23 May 2015, 08:21

#7 Post by scientist »

Flash,

This corrects that.

The 'grep design line' does not print

design capacity: 7800 Mah

that I would like.
count=1
done=0

while [ $count -le 10 ]
do
(( count++ ))

date "+ %m/%d/%y %r" >> Battery_State.txt

grep remaining /proc/acpi/battery/*/state >> Battery_State.txt
grep full /proc/acpi/battery/*/info >> Battery_State.txt
grep charging /proc/acpi/battery/*/state >> Battery_State.txt
grep design /proc/acpi/battery/*/capacity >> Battery_State.txt
sleep 300 # Update file every 5 minutes
done
Thanks,
Andy


Slacko 6.3.0 FULL INSTALL
JWM
File Manager - Thunar

ebisu
Posts: 176
Joined: Wed 25 Sep 2013, 05:06

#8 Post by ebisu »

Last edited by ebisu on Mon 01 Aug 2016, 07:59, edited 1 time in total.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#9 Post by Karl Godt »

I suggest that people drop the while test SOMETHING syntax .
Reason :
The loop needs to go until the end to be tested again.
Usually there are tests possible to break the loop before reaching the end.
Just
while true; do code; test || break; code; test || break; code; done
is simpler :

Code: Select all


_exit(){ echo "$*"; test -s /tmp/dir/your_file; exit $?; } #returns 0 if file has content

mkdir -p /tmp/dir  || _exit "Unable to create /tmp/dir"
touch /tmp/dir/your_file || _exit "Unable to open /tmp/dir/your_file"

trap "_exit 'Caught Signal'" INT TERM KILL

while :;
do

test -d  /proc/acpi/battery || { echo "/proc/acpi/battery missing'; break; }
grep -H '.' /proc/acpi/battery/*/state >>/tmp/dir/your_file || { echo "No state file"; break; }

sleep 300 # Update file every 5 minutes 
done
test -s /tmp/dir/your_file #returns 0 if file has content
Sophitist: Your count code actually works five times, then would skip 5 times and then finish.
So no need for the last five counts.
And done=0 is an unused variable.

gcmartin

#10 Post by gcmartin »

Could/would a cron job best achieve your resultant "log"? If a cron scipt, it only need be a couple lines and no testing/looping required.

So that it reflects a historical logging, would it be best to name your_file

Code: Select all

scriptname-or-purpose.log
Hope this is helpful
Last edited by gcmartin on Fri 15 Jan 2016, 06:53, edited 1 time in total.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#11 Post by amigo »

Done is a reserved shell keyword -use some other variable name besides 'done'.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#12 Post by greengeek »

Interesting idea. I have never known what my cpu temps are and it would be good to know. Unfortunately the script output seems to be missing the critical info on my system (Slacko 5.6 derivative). Maybe I lack the sensors software or interface?

Also - if you want to extend the script a little it could probably do with some method of checking whether or not the directory exists (which it didn't on my system so the script initially could not run correctly)
Attachments
output.jpg
(16.75 KiB) Downloaded 246 times

User avatar
Semme
Posts: 8399
Joined: Sun 07 Aug 2011, 20:07
Location: World_Hub

#13 Post by Semme »

You need lm_sensors, then run: sensors-detect to see whether you have any available kernel modules to load.
>>> Living with the immediacy of death helps you sort out your priorities. It helps you live a life less trivial <<<

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#14 Post by musher0 »

Hello scientist.

If ever you get tired of scripting ;), there's this ready-made, icon tray thingy called
gatotray. Exists in 32-bit and 64-bit.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#15 Post by musher0 »

Hello Semme.
Semme wrote:You need lm_sensors, then run: sensors-detect to see whether you have any available kernel modules to load.
Not necessarily. You can get some CPU temperature info
with the acpi utility.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#16 Post by Karl Godt »

You need to load the temperature kernel driver manually, since its modalias
is not recognized by the puppy boot scripts .
For intel P4 it was it87 and now it should be coretemp .

The temperature driver creates files in sysfs :

Code: Select all

#!/bin/ash

TEMP_FILES=`find /sys -type f -name "temp*_input"`
TEMP_FILES=`echo "$TEMP_FILES" | sed '/^$/d'`
test "$TEMP_FILES" || { echo "No temparature files found."; exit 1; }

while :;
do

 while :;
 do
 read -r tf;
 #echo tf=$tf
 test "$tf"    || break 1; #newline
 test -f "$tf" || break 2; #exit program
 echo -n $tf:;
 cat $tf;
 echo;
 sleep 2;
 done <<EoI
$TEMP_FILES
EoI

sleep 2
done
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal :P

gcmartin

CPU temperature tray option

#17 Post by gcmartin »

Gotta hand it to @Musher0 on this one. Although it does not produce a running logfile, it is useful and easily spotted.

Anyone else tried it?

The primary difference between what he has presented and the thread is his is constantly visible while this thread does not discuss temperature visibility.

I imagine, that if desired, his utility could provide a log as an option.

Nice!

Post Reply