Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 22 Oct 2017, 17:14
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Script sends CPU temps to file
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [17 Posts]   Goto page: 1, 2 Next
Author Message
scientist

Joined: 23 May 2015
Posts: 864

PostPosted: Wed 13 Jan 2016, 00:36    Post subject:  Script sends CPU temps to file  

This works but distorts CPUtemps icon a bit. Smile

Quote:
#!/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
Back to top
View user's profile Send private message 
ebisu

Joined: 25 Sep 2013
Posts: 173

PostPosted: Wed 13 Jan 2016, 02:43    Post subject:  

done=0 looks wrong. And why does it avoid writing when count=5? Who wrote this?
Back to top
View user's profile Send private message 
scientist

Joined: 23 May 2015
Posts: 864

PostPosted: Wed 13 Jan 2016, 12:39    Post subject:  

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.

Quote:
#!/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


Quote:
#!/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
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 12670
Location: Arizona USA

PostPosted: Wed 13 Jan 2016, 16:10    Post subject:  

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.
Back to top
View user's profile Send private message 
scientist

Joined: 23 May 2015
Posts: 864

PostPosted: Wed 13 Jan 2016, 16:41    Post subject:  

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.

Quote:
# 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
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 12670
Location: Arizona USA

PostPosted: Wed 13 Jan 2016, 21:10    Post subject:  

ebisu wrote:
...why does it avoid writing when count=5?...
Back to top
View user's profile Send private message 
scientist

Joined: 23 May 2015
Posts: 864

PostPosted: Wed 13 Jan 2016, 22:26    Post subject:  

Flash,

This corrects that.

The 'grep design line' does not print

design capacity: 7800 Mah

that I would like.

Quote:

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
Back to top
View user's profile Send private message 
ebisu

Joined: 25 Sep 2013
Posts: 173

PostPosted: Thu 14 Jan 2016, 00:42    Post subject:  


Last edited by ebisu on Mon 01 Aug 2016, 03:59; edited 1 time in total
Back to top
View user's profile Send private message 
Karl Godt


Joined: 20 Jun 2010
Posts: 4208
Location: Kiel,Germany

PostPosted: Thu 14 Jan 2016, 19:34    Post subject:  

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:


_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.
Back to top
View user's profile Send private message 
gcmartin

Joined: 14 Oct 2005
Posts: 6730
Location: Earth

PostPosted: Thu 14 Jan 2016, 23:24    Post subject:  

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:
scriptname-or-purpose.log
Hope this is helpful
_________________
Get ACTIVE Create Circles; Do those good things which benefit people's needs!
We are all related ... Its time to show that we know this!
3 Different Puppy Search Engines or use DogPile

Last edited by gcmartin on Fri 15 Jan 2016, 02:53; edited 1 time in total
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2593

PostPosted: Fri 15 Jan 2016, 02:39    Post subject:  

Done is a reserved shell keyword -use some other variable name besides 'done'.
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 4660
Location: Republic of Novo Zelande

PostPosted: Fri 15 Jan 2016, 13:37    Post subject:  

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)
output.jpg
 Description   
 Filesize   16.75 KB
 Viewed   197 Time(s)

output.jpg

Back to top
View user's profile Send private message 
Semme


Joined: 07 Aug 2011
Posts: 7775
Location: World_Hub

PostPosted: Fri 15 Jan 2016, 14:57    Post subject:  

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 <<<
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 10983
Location: Gatineau (Qc), Canada

PostPosted: Fri 15 Jan 2016, 16:17    Post subject:  

Hello scientist.

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

BFN.

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 10983
Location: Gatineau (Qc), Canada

PostPosted: Fri 15 Jan 2016, 16:21    Post subject:  

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
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [17 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0604s ][ Queries: 12 (0.0061s) ][ GZIP on ]