Saturday, April 20, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 5470  / 1 Year ago, sat, november 26, 2022, 3:51:23

I write a bash file thus:



#!/bin/bash         
echo 1000 |sudo tee /sys/class/backlight/intel_backlight/brightness


(that changes the screen's brightness)



I need it to run at startup, but because it requires the sudo pass-phrase I must enter the pass-phrase manually. How can I reform this code not to require the sudo pass-phrase at run time?


More From » bash

 Answers
1

For this particular problem, you could probably just stick echo 1000 > /sys/class/backlight/intel_backlight/brightness in /etc/rc.local (before the exit-line). That would run it on boot, as root before the desktop was loaded.



But in general (how do I run a script as root?) things are a bit sticker...



You could just run sudo ./myscript (by editing sudoers) but just allowing ./myscript to be run without a password would mean you (or a program running as you) could edit that file and suddenly you can run anything as root without going through the proper procedures. Uber-poor security.



Instead I would suggest:



sudo mv myscript /sbin/myscript
sudo chown root:root /sbin/myscript
sudo chmod 700 /sbin/myscript


The ch* commands now mean only root can read/run the script. Sticking it in /sbin/ is just incidental - you don't have to do that.



Now you need to edit /etc/sudoers. The Wiki has a good example and you'll just need to substitute the shutdown commands with your script's path (use a full, absolute path). NOPASSWD is the key keyword here. It allows you to run something as sudo without the password. So then you can just add sudo /sbin/myscript to your startup jibberyboo and you're flying.


[#39950] Sunday, November 27, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
repend

Total Points: 195
Total Questions: 113
Total Answers: 107

Location: Nicaragua
Member since Tue, Dec 8, 2020
3 Years ago
;