LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2008, 06:09 PM   #1
gvp87
Member
 
Registered: Mar 2007
Location: Boston
Distribution: Ubuntu Gutsy
Posts: 50

Rep: Reputation: 15
automate sudo


Ihave an extremely small python script(only about 5 or 6 lines) to toggle the system beep. The only problem is that user needs to be root! I want any user to be able to use it, or even for the script to be automatically activated at boot time. Maybe there's a way for init to run it?

In the script, I tried doing 'fakeroot sudo', because that command tends to work in some programs, but it still won't allow(i guess that makes sense since the user is basically altering the way the kernel works).

Like I said, my script is coded in Python - I'm not sure if a workaround would require me to use bash scripting perhaps? (which, by the way, i'm HORRIBLE at bash scripting!!! haha)

Here is the sourcecode below:


import os
import sys

os.system('fakeroot sudo')

if len(sys.argv) < 2:
print "\nToggles system beep\n\nUsage: beep [-on|-off]\n\n"
else:
if sys.argv[-1] == '-on':
os.system('modprobe pcspkr')
elif sys.argv[-1] == '-off':
os.system('rmmod pcspkr')





Let me know if you know of any workarounds!

thanks,
Giuseppe
 
Old 05-17-2008, 08:42 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I think fakeroot does not help in this case. It only makes your script depend on the package that provides fakeroot.

Why not configure sudo so that members of some group can run (only) your script as root without providing a password?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
LXer: sudo, or not sudo: that is the question LXer Syndicated Linux News 0 02-07-2008 05:40 PM
LXer: Speaking Unix, Part 6: Automate, automate, automate! LXer Syndicated Linux News 0 01-04-2007 09:54 AM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 03:20 PM
How would I automate this? onewhoknows Linux - Newbie 5 06-22-2004 04:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration