Help - Search - Members - Calendar
Full Version: Running Command Or Script As Root
Linuxhelp > Support > Technical Support
I need a way to run a script with root priveleges without being prompted for the root password.

Quick description of my problem: I have a KVM unit that allows me to share one monitor, keyboard and mouse between 2 machines (SuSE 8.1 and XP). When I use my KVM to switch back to my SuSE 8.1 machine, the mouse needs to be re-initialized - this is a known problem. The recommended way to reset the mouse is to press Ctrl-Alt-F1 to go to text mode, then Ctrl-Alt-F7 to go back to X. That works, but I found a command that resets the mouse: xmset -E

xmset can only be run when you have root privileges. I know I can run sux in a shell before executing xmset, but I need to do that without it prompting me for the root password because I want to use xbindkeys to assign a keystroke to do the whole thing. I have created a script file that does the sux and xmset commands, but it forces me to type the root password.

I am the only user on the machine, so security is not an issue - I set the whole thing up. The machine is not open to the world.

Anyone have any advice? I'm open to listening to other approaches if you think there is a better way to do what I'm trying to do.

Thanks for any help you can give.
if you have sudo installed, you can do this:

edit your /etc/sudoers file and add this line to the bottom of the file (you have to run the command visudo as root to edit the sudoers file):

username ALL=NOPASSWD:full_path_to_script

(substitute your username and path for username and full_path_to_script above)

Then ... use the command:

sudo full_path_to_script
Thank you. I will check that out tonight. I was able to get it working using "expect" last night, but your solution would be much cleaner.

Thanks again!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2017 Invision Power Services, Inc.