rc.local is run at system boot, so well before a user logs on.
You have two options for running the script. One is to use visudo(8) to set up the command to allow to be run, with a NOPASSWD:
tag in the command entry, and then just use sudo to start the command, perhaps from /etc/profile and whatever other files are needed for whichever shells people might use. It might be as simple as dropping something in /etc/profile.d/ if that exists. Eg, if everyone who logs in will be in group video
then when you run visudo
you'd want a rule like:
%video ALL=NOPASSWD: /path/to/Linux_Asus_AI_remote.py
and then you'd invoke with:
sudo /path/to/Linux_Asus_AI_remote.py
The other option is to use pam_exec
to run a command after login while still root; it's cleaner but more dangerous because if you make mistakes you can hose your system and be unable to login. If you want to examine this, read up on the PAM modules and how authentication and authorisation work and look in /etc/pam.d/; also, think carefully about how you'll restrict this to only happen for appropriate users.
Whichever method you choose, you'll probably want to make sure that this does not happen if logging in as root, to reduce the gunk that's involved in letting the admin user get into the system.
Best Answer
How about this? Check if
uid == 0
: