JP Vossen on 7 Nov 2016 17:18:08 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] LINUX LOW LEVEL PROGRAMMING QUESTION


On 11/07/2016 07:59 PM, Ronald P Guilmet wrote:
The problem:
I have a Dell laptop that I cannot adjust the screen brightness via the
settings shown to me. I can however change them by echoing a value to
the /sys/class/.... file. This is not distro specific, it doesn't work
in Ubuntu or Fedora. I am currently using Fedora 24.

suid is disabled in Bash for security reasons. I can execute an echo
<value> > /file/path and it works. If I put that in a bash script and
run it from the root command line, it will not execute. No errors, it
just won't change the values.

If you are root, either because you ran `su`, `sudo` or put something in root's crontab, I don't understand how it can work one way but not the other...

More below but you can NOT do it like: sudo echo '1' > /sys/class/file

But if you sudo the script itself it should work, I'd think.


My programming experience has not been low level, and this seems to be
low level programming. I have a familiarity with C, and I'm thinking I
will try that.

I've looked up solutions in the past, but they don't seem to work anymore.

To fix this, and to satisfy my love of playing with Linux, I was
thinking of writing a C program that either reads a config file, or a C
program that will accept a parameter (screen value) giving at runtime.

Anyone have any suggestions or comments?


There are some subtleties with the order in which the shell expands and handles arguments. The details are elsewhere but the implications are that you can NOT do things like:
	sudo rm /var/spool/mail/*
	sudo echo '1' > /sys/class/file
and similar.

For writing a file there's a common hack, and maybe it will help in this case:
	echo '1' | sudo tee /sys/class/file
	--or--
	echo '1' | sudo tee -a /sys/class/file

Note `tee -a` appends while `tee` simply truncates and the difference is kind of important to understand!

Later,
JP
--  -------------------------------------------------------------------
JP Vossen, CISSP | http://www.jpsdomain.org/ | http://bashcookbook.com/
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug