You are not logged in.

#1 2013-08-31 17:23:35

sPHERE
Member
From: Москва
Registered: 2008-07-01
Posts: 76
Website

BASH toggle script [SOLVED]

Hi,

I would like to create a simple bash script that I can bind to a Fn launch button on my laptop.

As of now, I have created two bash scripts.

performance.sh
and
powersave.sh

performance.sh
echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor   
echo -n 0 > /sys/devices/system/cpu/intel_pstate/no_turbo

powersave.sh
echo "powersave" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor   
echo -n 1 > /sys/devices/system/cpu/intel_pstate/no_turbo

I would like to have a script that toggles between these two scripts, that I can bind to a button, to control power savings on my laptop through a single button rather than binding aliases in my .bashrc.

I have no clue on how to do this..

If somebody has the time to help me out, I would greatly appreciate it!

Last edited by sPHERE (2013-09-02 16:47:23)

Offline

#2 2013-08-31 17:37:30

cookies
Member
Registered: 2013-01-17
Posts: 253

Re: BASH toggle script [SOLVED]

I use this to switch between powersave and ondemand

#! /bin/bash
GOV=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`

case $GOV in
  "ondemand")
    sudo cpupower --cpu all frequency-set -g powersave > /dev/null
  ;;
  "powersave")
    sudo cpupower --cpu all frequency-set -g ondemand > /dev/null
  ;;
  *)
    sudo cpupower --cpu all frequency-set -g powersave > /dev/null
  ;;
esac

GOV=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
echo "governor set to $GOV"

Check the path for the cat command and change the executed commands to your liking.

Last edited by cookies (2013-08-31 17:37:52)

Offline

#3 2013-08-31 18:00:38

sPHERE
Member
From: Москва
Registered: 2008-07-01
Posts: 76
Website

Re: BASH toggle script [SOLVED]

Worked perfectly! Thanks alot! SOLVED!

Offline

#4 2013-08-31 18:46:09

cookies
Member
Registered: 2013-01-17
Posts: 253

Re: BASH toggle script [SOLVED]

I'm delighted to hear that. Please remember to mark this thread as solved.

Offline

Board footer

Powered by FluxBB