You are not logged in.
I am fairly new to shell (bash) scripting, but i thought i would at least manage an if test, though i was proven wrong :/
I have been looking at this for way to long by now, and i am positive i am just missing the obvious, though I just cannot see where im wrong (checked alot of examples of similar bash scripts)
The problem is that the code runs as if the if statement is always true (as if the `cat /sys/.../scaling_governor` is never updated). So what I think might have a say is the fact that it gathers info from /sys/... since i have never done that before
#!/bin/bash
if [ `cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`="performance" ]
then
echo "conservative" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "conservative" >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
echo "conservative" >/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo "conservative" >/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
echo "cpu governor: conservative"
else
echo "performance" >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "performance" >/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
echo "performance" >/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
echo "performance" >/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
echo "cpu governor: performance"
fi
the code should "toggle" the governor for each core by checking 1 of them and applying it to all (I know the code probably looks sub-par, so if you can't handle it, please tell me how to improve it :P, or if there is a better solution to this whole thing altogheter)
Thanks in advance, and I will be trying to solve this in the mean time :)
Last edited by JulianNymark (2011-03-10 23:47:45)
When there is nothing left to do. Do nothing.
Offline
How about using ondemand instead without any shell scripts?
ᶘ ᵒᴥᵒᶅ
Offline
True, I suppose I should just find 1 mode to fit all my needs. But I like to keep my laptop in as powersaving of a state as possible for 99% of the time, this script is what I want to bind to that spare blue key on my pc, for those times I must have it running smoothly. (ie. not strictly needed)
So this isn't too important to solve atm. Thus I might just stick to conservative (as I mainly use a text editor anyway) Though im not giving up on this yet. (I spent so much time already D:)
When there is nothing left to do. Do nothing.
Offline
You forgot to add spaces around =
As for improvements, tee can write to multiple files, and it also writes to stdout: (untested)
[[ $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor) = performance ]] && new=conservative || new=performance
echo -n "cpu governor: "
echo $new | tee /sys/devices/system/cpu/*/cpufreq/scaling_governor
Offline
wow, that was a nice script , 3 lines.
It works perfectly, and ive learned quite a bit of scripting from it! thank you! this made my day
and again thanks for such fast responses, awesome forum!
When there is nothing left to do. Do nothing.
Offline
tee makes bash scripting so much cleaner, it saved me alot of work when I wrote a scale-adjusting script for my i7!
One thing you might like, to make it even cleaner, instead of echo'ing to the file directly, you can use "cpufreq-set -g performance -r" switching performance with whichever governor you want. This would be more useful if you have your power management utilities controlling cpu speed as well. (-g sets governor, -r copies to every cpu core that is physically the same, aka in my i7 it makes all 8 go to performance)
Team Ignition Kernel Developer
linux-ideapad developer/maintainer
Flame Kernel developer for Galaxy Nexus and Galaxy S3
Want a cheap, reliable VPS with AWESOME customer service?
Offline
I use the following one-liner to give a GUI selection, using zenity, and the relevant entries in /etc/sudoers:
sudo /usr/bin/cpufreq-set -r -g $(cpufreq-info -g | sed 's| |\n|g' | zenity --title 'cpufreq-set' --text "Current governor: "$(cpufreq-info -p | cut -d ' ' -f 3) --list --column "Choose governor:" 2>/dev/null)
Offline
That was a good idea AdmiralSpark (and also owain ), I didn't know that I could pass -r in cpufreq-set.
I really should be more thorough in my manual reading
I don't think i will be going for a GUI selection (though that is a good idea for this).
The next (and final) step for me would be to have some sort of pop-up message display what governor i switched to. (since I bound this to a button press event it will not display in active terminal?). But I havent really started looking into that yet, and should probably make another thread for that after i fail miserably .
Thanks again for the help & suggestions.
When there is nothing left to do. Do nothing.
Offline
The next (and final) step for me would be to have some sort of pop-up message display what governor i switched to. (since I bound this to a button press event it will not display in active terminal?). But I havent really started looking into that yet, and should probably make another thread for that after i fail miserably .
notify-send -t 10000 "my title" "my message"
Offline
Perfect!
Everything is now the way I want it.
yet again, thanks!
When there is nothing left to do. Do nothing.
Offline
EDIT: this message was a duplicate (managed to resend )
Last edited by JulianNymark (2011-03-11 17:06:27)
When there is nothing left to do. Do nothing.
Offline