Apr-02-2018, 11:01 AM
I want to use sudo su - username inside a python script and also I need to assign password(I won't hardcode this instead this will come from user input from GUI) as well to it in script itself.
Manual steps:
1.usera$ sudo su - userb
2.usera$ "Entering password"
3.userb$ ./file.sh
I want to do the above steps inside a python script.
I have tried with the below but it switch's to userb and it will halt and wont run ./file.sh , when I exit it run's file.sh
#!/usr/bin/python
import os
os.system("echo password| sudo -S su - userb")
os.system("sudo -S su - userb")
os.system("file.sh")
Please help!
Thanks
Manual steps:
1.usera$ sudo su - userb
2.usera$ "Entering password"
3.userb$ ./file.sh
I want to do the above steps inside a python script.
I have tried with the below but it switch's to userb and it will halt and wont run ./file.sh , when I exit it run's file.sh
#!/usr/bin/python
import os
os.system("echo password| sudo -S su - userb")
os.system("sudo -S su - userb")
os.system("file.sh")
Please help!
Thanks