ronnie
ronnie

Reputation: 1839

How to give sudo access to a bash script?

I have a bash script (chbr.sh) to change my display brightness from terminal as my brightness keys doesn't work.

sudo setpci -s 00:02.0 F4.B=30`

Now, every time I run that script it asks for my password, which I don't like. So, I googled a little and found out that one can edit /etc/sudoers file to disable the password feature.

So, I edited my sudoers file with the below content

ronnie ALL = (ALL) NOPASSWD: /home/ronnie/chbr.sh

Now when I run my script as ./chbr.sh it again asks for my password. So, is this not the right way to give sudo access to a bash script or what am I doing wrong here?

ronnie@ronnie:~$ ls -l chbr.sh
~rwxrwxr-x 1 ronnie ronnie 46 Jul 13 15:59 /home/ronnie/chbr.sh

Upvotes: 14

Views: 29545

Answers (3)

Jakob Guldberg Aaes
Jakob Guldberg Aaes

Reputation: 844

For anyone who stumbles into this old question. You don't need sudo to change the brightness. It can be done with the “light” program where the

light -A 5

increases brightness with 5 and

light -U 5

decreases the brightness with 5.

Upvotes: 1

Igor Chubin
Igor Chubin

Reputation: 64563

Your script is entirely correct, but you need to execute it with the full path:

$ sudo /home/ronnie/chbr.sh

Upvotes: 16

fragmentedreality
fragmentedreality

Reputation: 1317

Do you run sudo /home/ronnie/chbr.sh?

With the content of the file being

setpci -s 00:02.0 F4.B=30

Or you allow user ronnie to sudo setpci without password:

ronnie ALL = (ALL) NOPASSWD: /sbin/setpci <-- or whatever path your setpci resides in.

Upvotes: 4

Related Questions