Re: Auto start of a shell script implementing sudo
Reply #5 –
For openRC, the README explains:
/etc/local.d/README
$ cat /etc/local.d/test1.start
#!/bin/bash
(command to be run as root) &
exit 0
You might not want the & or exit 0, that's only an example. You should make it executable with chmod. You could include a time delay in a script or wait by looping over a sleep until some file or service exists if it has to run after something else, like when the desktop has started.
/usr/local/bin$ sudo chmod a+xs myscript
/usr/local/bin$ cat myscript
#!/bin/bash
sudo ls -a /root
setuid works but only on the script, not on binaries called by the script, so with sudo it works in the above test but not without, on my system anyway, I expect that behaviour can be configured somewhere. Usually setuid is discouraged if another method can be used instead as it can potentially be exploited I've read, however there are several red entries in my /bin from official packages so it must still have it's uses.