1

I have got a .sh-script, trying to make powertop changes permanent.

'auto' > '/sys/bus/pci/devices/0000:00:02.1/power/control';

the commands in this .sh-script are all of this type.

I have a systemd-service in /etc/systemd/system with this content:

[Unit]
Description=My Script
After=network.target

[Service]
Type=forking
ExecStart=/home/my_username/.autostart_sudo.sh

[Install]
WantedBy=multi-user.target

The script ".autostart_sudo.sh" is called correctly after boot, (for example "bluetooth off"-command in this file is called perfeclty) but the echo->-commands are not called successfully.

I noticed that typing

  sudo 'auto' > '/sys/bus/pci/devices/0000:00:02.1/power/control';

in a terminal gives a restriction-error, but

  sudo su
 'auto' > '/sys/bus/pci/devices/0000:00:02.1/power/control';

works.

how do I have to change my systemd+bash-script to get the powertop-changes working on boot?

Thanks in advance!

Edit:

Okay, I try to describe the flow again: I got the systemd service posted on top of this post. This service calls the ".autostart_sudo.sh" in my /home/user/.

There are plenty commands in this .autostart_sudo.sh looking like this:

echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:04:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:03:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1a.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:03.3/power/control';
(...)
thinkfan start

The "thinkfan start" needs also root-privileges to start correctly, this one works, but the "echo"-commands dont.

I also tryed

bash -c 'echo auto > /sys/bus/pci/devices/0000:00:1d.0/power/control;'
bash -c 'echo auto > /sys/bus/pci/devices/0000:00:1a.7/power/control;'
bash -c 'echo auto > /sys/bus/pci/devices/0000:00:1a.2/power/control;'
bash -c 'echo auto > /sys/bus/pci/devices/0000:00:02.0/power/control;'
bash -c 'echo auto > /sys/bus/pci/devices/0000:00:02.1/power/control;'  

doesnt work either :/

The sudo-test-stuff I mentioned above were just tests in a Terminal.

any advice?

7
  • 1
    Do you actually have 'auto' > '/sys/bus/pci/devices/0000:00:02.1/power/control' in your script or echo 'auto' > '/sys/bus/pci/devices/0000:00:02.1/power/control'? In any case, if your script is called by systemd, sudo should not be necessary. Dows it work if you just echo the commands into the files, with no sudo?
    – terdon
    Apr 22, 2013 at 16:03
  • no, the sudo-test was outside the script in a terminal. i have the systemd-service calling the script, where the "echo..."-commands are listed (without sudo).
    – breytex
    Apr 22, 2013 at 17:24
  • Still not sure I understand, could you give us the whole picture? What sudo test, I thought systemd was running this at startup? Could you maybe post the script? Or at least a minimal example that reproduces the problem?
    – terdon
    Apr 23, 2013 at 0:59
  • i tryed to make things more clear in my post-edit :-)
    – breytex
    Apr 23, 2013 at 8:42
  • Does echo 'auto' | sudo tee 'file' work?
    – ignis
    Apr 23, 2013 at 13:44

3 Answers 3

0

Are you sure that X-bit set for /home/my_username/.autostart_sudo.sh Keep in the mind that owner uid/gid of this script must be root to prevent shell code injection by malware. And

sudo echo 'auto' > '/sys/bus/pci/devices/0000:00:02.1/power/control';

won't work because '>' executed not by root. Try

sudo bash -c 'echo auto > /sys/bus/pci/devices/0000:00:02.1/power/control';
1
  • i tryed to make things more clear in my post-edit :-)
    – breytex
    Apr 23, 2013 at 8:41
0

Yea, my bad. I called tlp start after the Powertop-tweaks. Dint know that tlp would mess the settings up this bad. So, if you have the same problem: call tlp start

1
  • Well done for figuring it out. Could you give a bit more detail please? When were you calling tlp start before and when are you calling it now?
    – terdon
    Apr 24, 2013 at 1:03
0

So sad, finally I have to step in and answer this question...

Earlier I wasn't able to answer as I didn't have the reputation to answer questions, comment, upvote. So, if you want more answers then do upvote this answer

You have to do 2 things:

1) Automate giving password to every command requiring sudo privileges.

echo "PASSWORD" | sudo -S COMMAND

2) Give permissions to everyone to change content of each configuration file

chmod 666 File_Path

here is the code which works for me:

Change "PASSWORD" with your current account sudo password

#For File Permission Change

echo "PASSWORD" | sudo -S chmod 666 '/sys/class/scsi_host/host0/link_power_management_policy'
echo "PASSWORD" | sudo -S chmod 666 '/sys/class/scsi_host/host1/link_power_management_policy'
echo "PASSWORD" | sudo -S chmod 666 '/sys/module/snd_hda_intel/parameters/power_save'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/i2c/devices/i2c-5/device/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/usb/devices/3-1.6/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1b.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:16.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1f.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1c.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1f.2/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1c.2/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:14.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1d.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:06:00.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:03.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:00.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1c.3/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:07:00.0/power/control'
echo "PASSWORD" | sudo -S chmod 666 '/sys/bus/pci/devices/0000:00:1c.4/power/control'

#For Actual Modification

echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy'
echo 'min_power' > '/sys/class/scsi_host/host1/link_power_management_policy'
echo '1' > '/sys/module/snd_hda_intel/parameters/power_save'
echo 'auto' > '/sys/bus/i2c/devices/i2c-5/device/power/control'
echo 'auto' > '/sys/bus/usb/devices/3-1.6/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1b.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:16.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.2/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:06:00.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:03.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.3/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:07:00.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.4/power

Note: you may have to change the whole commands as per your system :)

2
  • As long as you aren’t banned or suspended, you always have permission to answer any question (that isn’t locked or protected). Dec 11, 2017 at 18:58
  • Anyway, did my new code work for you? Dec 11, 2017 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .