Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by jasonwryan, Michael Mrozek Sep 5 '12 at 4:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Thanks so much. I decided to use sudo bash -c "..." to do the job. But the first time, it ask password but after this, does not. Any idea? –  Sigur Sep 5 '12 at 2:09
1  
You could also look at xbacklight to manage this for you... –  jasonwryan Sep 5 '12 at 3:53
    
@Sigur sudo caches your credentials when you use it, so it won't ask for a password again for a while. You can use sudo -k to make it forget –  Michael Mrozek Sep 5 '12 at 4:02

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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 5 '12 at 11:39
    
@Sigur mistake, should be visudo –  warl0ck Sep 5 '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 5 '12 at 11:52
    
@Sigur you need to replace that with your actual login name –  warl0ck Sep 5 '12 at 12:00
    
It's not working. Should I reboot or closing terminal is enough? It's still asking pwd. –  Sigur Sep 5 '12 at 12:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.