You are not logged in.

#1 2012-12-07 08:18:16

sjobol
Member
Registered: 2012-12-07
Posts: 3

[SOLVED] Starting .sh file at login

Hello all!

First post here and wanted to thank everyone for already providing me with some great solutions on these forums :-)

All pleasantries aside, i'm faced with the following problem i haven't been able to find a solution for:

In order to get my FNkey brightness to work i have to make my brightness file writable by myself in order to echo certain values to it.

I tried to do this by making a .sh file containing

sudo chmod 777 /path/to/brightnessfile

Then adding this file to my ~/.xinitrc by adding the line :

sh /home/sbolluijt/Templates/enable-brightness.sh

In order to make this file executable without a sudo command i added

sbolluijt ALL=(ALL) NOPASSWD: /Templates/enable-brightness.sh

to /etc/sudoers

Now surely i am missing something. when executing the self-made enable-brightness.sh file i still get asked for a password. my FN brightness DOES work fine after that.
However i cannot alter my brightness at start-up (which i expect this to do)

Can anyone help me out?

Kind regards and thanks in advance


*edited for code brackets

Last edited by sjobol (2012-12-07 09:30:53)

Offline

#2 2012-12-07 09:05:07

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,538

Re: [SOLVED] Starting .sh file at login

Did you try specifying the full path /home/sbolluijt/Templates/enable-brightness.sh in /etc/sudoers?

Offline

#3 2012-12-07 09:14:20

sjobol
Member
Registered: 2012-12-07
Posts: 3

Re: [SOLVED] Starting .sh file at login

I just did;

sbolluijt ALL=(ALL) NOPASSWD: /home/sbolluijt/Templates/enable-brightness.sh

But still didn't work.
There must be something wrong with the sudoers part though, since executing

sh /home/sbolluijt/Templates/enable-brightness.sh

still asks me for my password.

Offline

#4 2012-12-07 09:14:56

hunterthomson
Member
Registered: 2008-06-22
Posts: 794
Website

Re: [SOLVED] Starting .sh file at login

First and maybe the source of the problem, you do not want to run a script automatically as root that is writable by a non-root user.

Put the script at:

/usr/local/bin/enable-brightness.sh

And make it owned and only executable & readable by root

chown root:root /usr/local/bin/enable-brightness.sh
chmod 750 /usr/local/bin/enable-brightness.sh

Not in your user's home folder.

Second. Instead of making the file World writable, i.e. chmod 777 instead make it group writable and add yourself to that group, or maybe just make it a group you already belong to like users or wheel

#!/bin/bash
chmod 664 /path/to/brightnessfile
chown root:wheel /path/to/brightnessfile
exit 0

Third, if you really just want this script to run every boot then configure systemd to do it. That way you do not need to edit the sudoers file at all because systemd will run it as Root.

/usr/lib/systemd/system/enable-brightness.service

[Unit]
Description=Allow user to set brightness

[Service]
Type=simple
RemainAfterExit=no
ExecStart=/usr/local/bin/enable-brightness.sh

[Install]
WantedBy=multi-user.target

Then enable it...

systemctl enable enable-brightness.service
systemctl start enable-brightness.service

Last edited by hunterthomson (2012-12-07 09:30:02)


OpenBSD-current Thinkpad X230, i7-3520M, 16GB CL9 Kingston, Samsung 830 256GB
Contributor: linux-grsec

Offline

#5 2012-12-07 09:29:30

sjobol
Member
Registered: 2012-12-07
Posts: 3

Re: [SOLVED] Starting .sh file at login

That worked like a charm hunterthomson!

I'll go look into building your own .service files, that'll probably make my life easier next time i want to do such a thing.

marking as solved!

Offline

#6 2012-12-07 09:31:44

hunterthomson
Member
Registered: 2008-06-22
Posts: 794
Website

Re: [SOLVED] Starting .sh file at login

Cool, ya systemd is a big change from systemv but it is nice after you get use to it.

I keep all my scripts that I write in /usr/local/bin that way they are easy to find and stuff. I think like it is where they should be anyway.

NOTE: I just made some edits to my post. You may want to check them out


OpenBSD-current Thinkpad X230, i7-3520M, 16GB CL9 Kingston, Samsung 830 256GB
Contributor: linux-grsec

Offline

Board footer

Powered by FluxBB