0

I have a python script that restarts the mouse driver

import os

os.system("sudo modprobe -r psmouse")
os.system("sudo modprobe psmouse")

since my mouse doesn't always show up on start. What is a way I can run it on start up without being prompted for a password?

3 Answers3

0

You can edit your sudoers file so that a given user can execute a specific script without a password request.

Example:

someusername    ALL=(ALL) NOPASSWD: /some/path/to/script/somescript

Similar Post / Reference: How do I sudo a command in a script without being asked for a password?

Mark
  • 1,502
  • If it's a dupe, please mark it as such, instead of re- answering. – Jacob Vlijm Dec 16 '16 at 18:58
  • It is not a dupe of the question you linked. The person asking a question simply asked it wrong. OP should have asked, "how do I load a kernel module on boot? – Sam Gleske Dec 16 '16 at 19:24
0

If you just want to reload the mouse drive on start up, it may be more convenient to include the commands in /etc/rc.local. rc.local runs as root, so you don't need any sudo commands. By default it just contains comments and and exit 0 command. Assuming that you have the default rc.local, edit it to look (something like) like this:

#!/bin/sh -e
modprobe -r psmouse
modprobe psmouse
exit 0
muru
  • 197,895
  • 55
  • 485
  • 740
Nick Sillito
  • 1,596
0

OP should have asked, "how do I load a kernel module on boot?"

Edit the /etc/modules file and add the name of the module (without the .ko extension) on its own line. On boot the kernel will try to load all the modules named in this file.

Source: How to install 3rd party module so that it is loaded on boot?