LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-22-2016, 12:48 AM   #1
bobdxcool
LQ Newbie
 
Registered: Jun 2014
Posts: 5

Rep: Reputation: Disabled
Return from root to user using python os.system('kill') not working


I need to run a command from my python script as a root user (just sudo wont work), so I use os.system('sudo su') and am able to get root access. But again I need to return back to user . I tried os.system('exit'), but it still doesnt come out of root login to user login. I have to manually enter exit in the terminal to get back to user login. Can someone help me on how to do this in python ?

Code:
import os
import time
os.system('clear')#clear the terminal
os.system('sudo eject /dev/sr0')
time.sleep(2)
os.system('sudo modprobe option')
time.sleep(2)
os.system('sudo su')
time.sleep(5)
os.system('echo 2001 7d0e > /sys/bus/usb-serial/drivers/option1/new_id')
time.sleep(2)os.system('exit')
 
Old 09-22-2016, 02:26 AM   #2
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 363Reputation: 363Reputation: 363Reputation: 363
I think you need the PARENT pid, which is the sudo-su'ed shell.
os.kill(-9, os.getppid())

...MAYBE... (other replys welcome!)
 
  


Reply

Tags
exit, python, root


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
System call killall (that kill all user processes) s@linux Linux - Kernel 6 05-05-2016 10:17 AM
startx from root user is working while from sudo user not unkn(0)wn Linux - Newbie 2 08-17-2012 09:31 PM
[SOLVED] Python gconf not working when ran as root figure002 Programming 5 08-04-2010 06:41 AM
Software working in root but not working in user accounts Heshsham Linux - Software 3 05-29-2010 02:58 AM
python: return not returning bulliver Programming 1 01-09-2003 06:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:10 PM.

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