You use
sudo to run the script with elevated access privileges.
A simple way to do that is as follows. First, put the privileged stuff in a separate script, say
/usr/local/bin/do-the-sys-stuff:
Code:
#!/bin/bash
[ "`id -u`" = "0" ] || exec sudo -- "$0" "$@"
# do the /sys stuff here
The second line causes the script to rerun itself via
sudo if run without root privileges.
Then, allow any user to use sudo to run that script as root without a password, by adding line
Code:
ALL ALL = (root) NOPASSWD: /usr/local/bin/do-the-sys-stuff
into
/etc/sudoers.d/allow-do-the-sys-stuff if
/etc/sudoers.d/ exists, in
/etc/sudoers otherwise. If you create a new file, make sure it is owned by root and has mode 0440:
chown 0:0 file && chmod 0440 file
After that, any user can run
/usr/local/bin/do-the-sys-stuff as themselves, causing it to rerun itself with root privileges via sudo, and doing your /sys stuff with root privileges.
Questions?