You are not logged in.
First off, I'm not a programmer. I don't know how to script. I'm pretty much a dumb noob right now. Anyhow, I'm using dwm and just dumped conky in favor of a status script to try to learn a little more (and it seemed like a good idea anyway). I was looking for a simple cpu temp script and couldn't really find one (maybe I didn't look very hard), so I put one together myself using a couple other simple ones that I use as examples. This is what I came up with:
temp(){
temp="$(acpi -t | awk '{print $4}')"
echo -e "\x01temp\x02$temp°\x01"
}
It seems to work ok. I guess my question is, does it look alright? I mean, is there anything wrong with it? Also, it's kinda silly, but can I get rid of the .0 at the end of the reading some how? Here's a screenshot.
I also put together another simple one for the hard drive temp.
hdd(){
hdd="$(hddtemp /dev/sda | awk '{print $4}')"
echo -e "\x01hdd\x02$hdd\x01"
}
I'm pretty sure it will work but evidently it needs root access. What would be the best way to do that? With sudo or maybe change permission of hddtemp? Or is there a better way to do the script altogether? I would prefer something as simple as possible for now. Thanks for any help or suggestions. BTW, I do plan on learning some basic scripting soon. My feeble old brain can only handle so much.
Last edited by stlarch (2011-04-05 18:00:23)
Offline
I got some great pointers in this thread: it's well worth a read https://bbs.archlinux.org/viewtopic.php?id=110788
It's not particularly elegant, but you could use cut to remove the .0 from your temp reading.
Offline
the temp function could be done like this, which will also get rid of the .0:
temp()
{
acpi -t | awk '{ printf("\x01temp\x02%d°\x01", $4)}'
}
I for my part would go for the sudo route with hddtemp, doing the function like this (getting rid of extra call to awk by using hddtemp -n switch):
hdd()
{
echo -e "\x01hdd\x02$(sudo hddtemp -n /dev/sda)\x01"
}
My System: Dell XPS 13 | i7-7560U | 16GB RAM | 512GB SSD | FHD Screen | Arch Linux
My Workstation/Server: Supermicro X11SSZ-F | Xeon E3-1245 v6 | 64GB RAM | 1TB SSD Raid 1 + 6TB HDD ZFS Raid Z1 | Proxmox VE
My Stuff at Github: github
My Homepage: Seiichiros HP
Offline
For a non-sudo solution I would recommend using hddtemp as daemon
Arch64/DWM || My Dropbox referral link
Offline
Sorry it took me so long to reply. Thanks for everything! jasonwryan, I read through the thread and I found a couple other recommended places to start in another thread, Greg's Wiki, and the Bash Hackers Wiki. I got the inspiration to try this from you in the first place and some other stuff too. And thanks to Procyon for the cpu usage script. Thanks again.
seiichiro0185, the one for the cpu temp seems to work nicely. Thank you. I'm sure the other one should work with sudo but I'm still not sure if that's the best way.
JokerBoy, I forgot to mention before that I do have it running as a daemon. I can run hddtemp but when I try to access /dev/sda it says permission denied. So I'm thinking it's maybe something with the permissions on /dev/sda and not a problem with hddtemp? I'll keep trying to figure it out. Any ideas would be appreciated.
Offline
Please, read the wiki.
Running the daemon gives you the possibility to access the temperature via an TCP/IP request, so you could use this in order to check the temperature from outside, or within some scripts.
Arch64/DWM || My Dropbox referral link
Offline
As pointed out by jokerboy hddtemp won't work without root even with the daemon running.
You need to get the values using tcp/ip. Here is a line to do just this for the first configured hdd:
hdd()
{
telnet 127.0.0.1 7634 2>/dev/null | awk '/dev/ { split($0,hd,"|"); printf("\x01hdd\x02%d°\x01", hd[4]) }'
}
obviously a telnet client needs to be installed for this to work
My System: Dell XPS 13 | i7-7560U | 16GB RAM | 512GB SSD | FHD Screen | Arch Linux
My Workstation/Server: Supermicro X11SSZ-F | Xeon E3-1245 v6 | 64GB RAM | 1TB SSD Raid 1 + 6TB HDD ZFS Raid Z1 | Proxmox VE
My Stuff at Github: github
My Homepage: Seiichiros HP
Offline
Thanks for pointing that out JokerBoy, I was confused. I get it now. I was actually reading it while you responed seiichiro0185, and I installed netcat instead of telnet. I was trying to figure a way to get netcat to do it. I hate to ask you for that after you just wrote one for telnet. Is one way superior to the other, or does it matter? I can try the telnet way. What telnet client would you recommend? I'm not familiar with them. Thanks
edit: I've never used telnet and don't really know much about it. I've read that it's not secure, but I don't know if that would be the case in my situatution?
Last edited by stlarch (2011-04-05 17:39:13)
Offline
telnet and netcat can be swapped out in my line above, just put nc instead of telnet and it should work. There shouldn't be a noticeable difference speed- ot resource-wise I think
regarding the security: telnet is not secure for login on remote machines, since it's not encrypted in any way. For reading values from a locally running daemon this doesn't matter since no sensitive data like passwords/login names are transfered and the traffic will never leave the machine.
My System: Dell XPS 13 | i7-7560U | 16GB RAM | 512GB SSD | FHD Screen | Arch Linux
My Workstation/Server: Supermicro X11SSZ-F | Xeon E3-1245 v6 | 64GB RAM | 1TB SSD Raid 1 + 6TB HDD ZFS Raid Z1 | Proxmox VE
My Stuff at Github: github
My Homepage: Seiichiros HP
Offline
seiichiro0185, you're awesome! It works. I would have never come up with those on my own right now. I'll go ahead and mark this as solved. Thanks JokerBoy and jasonwryan. I see lots of reading in my future.
Offline
First off, I'm not a programmer. I don't know how to script. I'm pretty much a dumb noob right now. Anyhow, I'm using dwm and just dumped conky in favor of a status script to try to learn a little more (and it seemed like a good idea anyway). I was looking for a simple cpu temp script and couldn't really find one (maybe I didn't look very hard), so I put one together myself using a couple other simple ones that I use as examples. This is what I came up with:
temp(){ temp="$(acpi -t | awk '{print $4}')" echo -e "\x01temp\x02$temp°\x01" }
It seems to work ok. I guess my question is, does it look alright? I mean, is there anything wrong with it? Also, it's kinda silly, but can I get rid of the .0 at the end of the reading some how? Here's a screenshot. http://ompldr.org/tODRldQ
I also put together another simple one for the hard drive temp.
hdd(){ hdd="$(hddtemp /dev/sda | awk '{print $4}')" echo -e "\x01hdd\x02$hdd\x01" }
I'm pretty sure it will work but evidently it needs root access. What would be the best way to do that? With sudo or maybe change permission of hddtemp? Or is there a better way to do the script altogether? I would prefer something as simple as possible for now. Thanks for any help or suggestions. BTW, I do plan on learning some basic scripting soon. My feeble old brain can only handle so much.
I'm trying to do the same thing right now, could you please tell me where should I put this code?
temp(){
temp="$(acpi -t | awk '{print $4}')"
echo -e "\x01temp\x02$temp°\x01"
}
I've already patched my config.h with "dwm-5.8.2-statuscolors.diff"
My dwm output is generated by a script, that I made and put into /usr/sbin/, here it is:
while true
do
xsetroot -name "`cat /proc/acpi/ibm/thermal | awk '{print "cpu cores: "$3":"$4}' ` `df -h / | awk 'END {print "| root use: " $5}' | sed 's/Use%//'` `df -h /home| awk 'END {print " home use: " $5}' | sed 's/Use%//'` `date | awk 'END {print "| " $1" "$2" "$3" "}'` `uptime | awk 'BEGIN {FS = ":"}; END {print"|"$1":"$2}'`"
sleep 20
done
lenovo thinkpad EDGE 13'
Offline
Well, I'm the wrong person to ask for help with scripting. But you could maybe put something like this in your script:
xsetroot -name "$echo $(acpi -t | awk '{printf ("\x01%d"), $4}')°"
The \x01 would represent the first color defined in your config.h. \x02 would represent the second defined color, etc. You can look at my configs to see how I do it. I didn't write any of it. I borrowed it from others and put it together. Hope it helps. Maybe someone more knowledgeable can help you better.
Last edited by stlarch (2011-05-15 03:35:49)
Offline
Well, I'm the wrong person to ask for help with scripting. But you could maybe put something like this in your script:
xsetroot -name "$echo $(acpi -t | awk '{printf ("\x01%d"), $4}')°"
The \x01 would represent the first color defined in your config.h. \x02 would represent the second defined color, etc. You can look at my configs to see how I do it. I didn't write any of it. I borrowed it from others and put it together. Hope it helps. Maybe someone more knowledgeable can help you better.
thank you a lot, I will keep it in mind
lenovo thinkpad EDGE 13'
Offline