0

Possible Duplicate:
Redirecting stdout to a file you don't have write permission on

I am creating a script to change the brightness of my laptop. I discovered that I can do this using

echo 1000  > /sys/class/backlight/intel_backlight/brightness

for example. But I must to do this as root, not with sudo command. Well, I created the file /usr/bin/brilho containing

echo "$1"  > /sys/class/backlight/intel_backlight/brightness

and now I can execute it with brilho 1000. But the problem is the permission. This does not work with sudo brilho 1000 neither brilho 100. Again I have to change to root.

So, I would like to know how to improve this to facilitate my job.

Regards and thanks.

Sigur
  • 2,431

1 Answers1

1

To allow arbitrary user to change brightness, you could setup sudo, invoke visudo to launch the editor, and put the following line at the end:

username ALL=NOPASSWD: /usr/bin/tee /sys/class/backlight/intel_backlight/brightness

And the script will be:

echo $value | sudo tee /sys/class/backlight/intel_backlight/brightness

Which will no longer ask your password

daisy
  • 54,555
  • sudoedit returns usage: sudoedit [-AknS] [-C fd] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file .... I should open what file to add that line? – Sigur Sep 05 '12 at 11:39
  • @Sigur mistake, should be visudo – daisy Sep 05 '12 at 11:40
  • I'd added that line. It's working when root user but still is asking pass when normal user. Well, one more question: should I write username or my_username? – Sigur Sep 05 '12 at 11:52
  • @Sigur you need to replace that with your actual login name – daisy Sep 05 '12 at 12:00
  • It's not working. Should I reboot or closing terminal is enough? It's still asking pwd. – Sigur Sep 05 '12 at 12:03
  • @Sigur try again, code edited, just found tee was in /usr/bin/tee instead of /bin/tee on Ubuntu – daisy Sep 05 '12 at 12:06
  • Perfect! Thanks so much. It's working now. Best wishes. – Sigur Sep 05 '12 at 12:08